Click here to Skip to main content
14,392,749 members
Rate this:
Please Sign up or sign in to vote.
See more:
I have designed a simple front page in asp.net

I have already created a databse named Reg which takes the values from this form

Its a simple registration form

Code:

<html>
<head>
<meta name="GENERATOR" content="Microsoft FrontPage 5.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>New Page 1</title>
</head>
<body>
<form name="frmReg" method="POST" action="--WEBBOT-SELF--">
  <!--webbot bot="SaveResults" u-file="C:\Documents and Settings\Administrator\Desktop\reg\_private\form_results.csv" s-format="TEXT/CSV" s-label-fields="TRUE" --><table class="style1">
           <tr>
                <td>
                    Name:</td>
                <td>
                    <asp:TextBox ID="TxtName" runat="server">
                    <input type="text" name="T1" size="20"></asp:TextBox></td>
                    <asp:RangeValidator ControlToValidate="TxtName" MinimumValue="A" MaximumValue="Z" Type="Text" EnableClientScript="false" Text="Only Alphabets!" runat="server" />

            </tr>
            <tr>
                <td>
                    Address:</td>
                <td>
                    <textarea rows="2" name="S1" cols="20"></textarea></td>
<asp:RangeValidator ControlToValidate="TxtAddress" MinimumValue="A,a" MaximumValue="Z,z" Type="Text" EnableClientScript="false" Text="Only Alphabets!" runat="server" />

            </tr>
            <tr>
                <td>
                   Email:</td>
                <td>
            <asp:TextBox ID="Txtemail" runat="server">
            <input type="text" name="T3" size="20"></asp:TextBox></td>
<asp:RangeValidator ControlToValidate="Txtemail" MinimumValue="A,a" MaximumValue="Z,z" Type="Text" EnableClientScript="false" Text="Only Alphabets!" runat="server" />

            </tr>
            <tr>
                <td>
                    Password:</td>

                <td>
            <asp:TextBox ID="TxtPassword" runat="server" TextMode="Password">
            <input type="text" name="T4" size="20"></asp:TextBox></td>
            </tr>
            <tr>
                <td>
                    Age:</td>
                <td>
                    <asp:TextBox ID="TxtAge" runat="server">
                    <input type="text" name="T5" size="20"></asp:TextBox></td>
<asp:RangeValidator ControlToValidate="TxtAge" MinimumValue="0" MaximumValue="9" Type="number" EnableClientScript="false" Text="Only number!" runat="server" />

            </tr>
            <tr>
                <td>
                    Gender:</td>
                <td>
                <select size="1" name="D1">
                <option>Male</option>
                <option>Female</option>
                </select></td>
            </tr>
        </table>
    <p><input type="submit" value="Submit" name="B1" onclick=Submit()><input type="reset" value="Reset" name="B2"></p>
</form>
</body>
</html>


Jst write the code for connecting to database and
inserting data into database on Submit.
Posted
Updated 6-Jul-10 22:00pm
v2
Rate this:
Please Sign up or sign in to vote.

Solution 1

To implement it using LINQ will shows like

using(SomeDataContext db=new SomeDataContext())
{ 
var newUser=new UserBO{Username="John", Email="john@gmail.com"};
db.Users.InsertOnSubmit(newUser);
db.SubmitChanges();
}


where SomeDataContext - DataContext object that is creating where you drag the table USERS from Server explorer to your .dbml (LINQ to SQL class) file
   
v2
Rate this:
Please Sign up or sign in to vote.

Solution 4

 string conString = System.Configuration.ConfigurationManager.AppSettings["ConnectionString"];  //this is the connection string defined in web.config

SqlConnection sqlConn = new SqlConnection(conString);
sqlConn.Open();
SqlCommand cmd= new SqlCommand("insert into table_name values('"+TxtName.Text+"','"+TxtAddress.Text+"'',"+TxtEmail.Text+"','"+TxtPassword.Text+"','"+TxtAge.Text+"','"+D1.SelectedItem.Text+"'", sqlConn);//The sequence of fields may vary as per the sequence in your DB table

cmd.ExecuteNonQuery();// this returns values greater than 1 if values are sucessfully inserted in DB


The above code will help you insert values in the db table.

The above code is just an example , make sure that you make the changes in it as per your requirements.
   
v2
Rate this:
Please Sign up or sign in to vote.

Solution 2

i m currently using Microsoft FRONTPAGE.

Shud i write this code above the previous code?

Please specify the changes required.......


Thanks....
   
Comments
Sandeep Mewara 7-Jul-10 16:55pm
   
Reason for my vote of 1
This should be a comment and not answer. Posting as a comment also triggers a mail to the person whom you want to discuss the answer with.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100