locked
How to submit this form value in database..? and how to insert reset button in this code? RRS feed

  • Question

    1. how to submit filling form data in to database ?
    2. my reset button is not working how to make enable reset button?
    3. can we see data under submit button ?

    Default.aspx code is hear

    <%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
        <title>Untitled Page</title>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
            <asp:Label ID="Label" runat="server" Style="z-index: 100; left: 142px; position: absolute;
                top: 25px" Text="Hello World"></asp:Label>
            <asp:TextBox ID="nameTextBox" runat="server" Height="19px" Style="z-index: 101; left: 169px;
                position: absolute; top: 80px" Width="149px"></asp:TextBox>
            <asp:TextBox ID="emailtaxtbox" runat="server" Height="19px" Style="z-index: 102;
                left: 169px; position: absolute; top: 129px" Width="149px"></asp:TextBox>
            <asp:Label ID="Namelabel" runat="server" Style="z-index: 103; left: 41px; position: absolute;
                top: 85px" Text="Name"></asp:Label>
            <asp:Label ID="EmailLabel" runat="server" Height="19px" Style="z-index: 104; left: 41px;
                position: absolute; top: 134px" Text="Email"></asp:Label>
            &nbsp;
            <asp:TextBox ID="passwordTextBox" runat="server" Height="19px" MaxLength="10" Style="z-index: 105;
                left: 169px; position: absolute; top: 174px" TextMode="Password" Width="149px"></asp:TextBox>
            <asp:TextBox ID="conformpasswordTextBox" runat="server" Height="19px" MaxLength="10"
                OnTextChanged="conformpasswordTextBox_TextChanged" Style="z-index: 106; left: 169px;
                position: absolute; top: 224px" TextMode="Password" Width="149px"></asp:TextBox>
            <asp:Label ID="passwordLabel" runat="server" Height="19px" Style="z-index: 107; left: 41px;
                position: absolute; top: 184px" Text="Password"></asp:Label>
            <asp:Label ID="ConformpasswordLabel" runat="server" Height="19px" Style="z-index: 108;
                left: 41px; position: absolute; top: 231px" Text="Conform Password"></asp:Label>
            &nbsp;
            <asp:Button ID="Submitbutton" runat="server" Style="z-index: 109; left: 169px; position: absolute;
                top: 407px" Text="Submit" OnClick="Submitbutton_Click" />
            <asp:HyperLink ID="HyperLink" runat="server" NavigateUrl="http://www.oceninfo.co.cc" Style="z-index: 110;
                left: 284px; position: absolute; top: 359px">For More Information</asp:HyperLink>
            <asp:CheckBox ID="acceptCheckBox" runat="server" Style="z-index: 111; left: 169px;
                position: absolute; top: 365px" Text="I Accept" />
            <asp:DropDownList ID="DropDownList" runat="server" Style="z-index: 112; left: 169px;
                position: absolute; top: 272px">
                <asp:ListItem>Country List...</asp:ListItem>
                <asp:ListItem>UK</asp:ListItem>
                <asp:ListItem>USA</asp:ListItem>
                <asp:ListItem>India</asp:ListItem>
                <asp:ListItem>Pakistan</asp:ListItem>
                <asp:ListItem>Australiya</asp:ListItem>
                <asp:ListItem>None Of this</asp:ListItem>
            </asp:DropDownList>
            <asp:Label ID="CountryLabel" runat="server" Style="z-index: 113; left: 41px; position: absolute;
                top: 273px" Text="Country"></asp:Label>
            <asp:RequiredFieldValidator ID="NameRequiredFieldValidator" runat="server" ControlToValidate="nameTextBox"
                ErrorMessage="Name Required" Style="z-index: 114; left: 341px; position: absolute;
                top: 83px">*</asp:RequiredFieldValidator>
            <asp:RequiredFieldValidator ID="EmailRequiredFieldValidator" runat="server" ControlToValidate="emailtaxtbox"
                ErrorMessage="Email Required" Style="z-index: 115; left: 341px; position: absolute;
                top: 131px">*</asp:RequiredFieldValidator>
            <asp:RequiredFieldValidator ID="passwordRequiredFieldValidator" runat="server" ControlToValidate="passwordTextBox"
                ErrorMessage="Password Required" Style="z-index: 116; left: 341px; position: absolute;
                top: 181px">*</asp:RequiredFieldValidator>
            <asp:CompareValidator ID="CompareValidator1" runat="server" ControlToValidate="DropDownList"
                ErrorMessage="Select Your Country" Operator="NotEqual" Style="z-index: 117; left: 341px;
                position: absolute; top: 275px" ValueToCompare="Country List..."></asp:CompareValidator>
            <asp:RadioButton ID="YesRadioButton" runat="server" Style="z-index: 118; left: 169px;
                position: absolute; top: 309px" Text="Yes" ValidationGroup="Prince" />
            <asp:RadioButton ID="NoRadioButton" runat="server" Height="20px" Style="z-index: 119;
                left: 225px; position: absolute; top: 309px" Text="No" ValidationGroup="Prince"
                Width="44px" />
            <asp:ValidationSummary ID="ValidationSummary1" runat="server" Style="z-index: 120;
                left: 375px; position: absolute; top: 81px" />
            <asp:Label ID="Submitlabel" runat="server" ForeColor="DarkSlateGray" Style="z-index: 121;
                left: 305px; position: absolute; top: 408px"></asp:Label>
            &nbsp;
            <asp:CompareValidator ID="conformPasswordCompareValidator" runat="server" ControlToCompare="passwordTextBox"
                ControlToValidate="conformpasswordTextBox" ErrorMessage="Password Not Match Refrash page"
                Style="z-index: 122; left: 343px; position: absolute; top: 225px"></asp:CompareValidator>
            &nbsp; &nbsp;&nbsp;&nbsp;
            <asp:Button ID="ResetButton" runat="server" Style="z-index: 124; left: 235px; position: absolute;
                top: 407px" Text="Reset" />
        
        </div>
        </form>
    </body>
    </html>
    

    Default.aspx.cs code is hear...

    using System;
    using System.Data;
    using System.Configuration;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;
    
    public partial class _Default : System.Web.UI.Page 
    {
        protected void Page_Load(object sender, EventArgs e)
        {
    
        }
        protected void conformpasswordTextBox_TextChanged(object sender, EventArgs e)
        {
            
        }
       
        protected void Submitbutton_Click(object sender, EventArgs e)
        {
            Submitlabel.Text = "Submit Success!";
        }
        
    }
    

    please gave me step by step instruction...Thanks In Advance

    Monday, April 23, 2012 6:40 AM

Answers

  • Above links are already having some sample code:

    First add System.Data in your project and add System.Data.SqlClient on your .cs file

    string con="user id=sa; password=; Data Source=your database server name; Initial Catalog=your database name";

    System.Data.SqlClient.SqlConnection sqlConnection1 = new System.Data.SqlClient.SqlConnection(con); System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand(); cmd.CommandType = System.Data.CommandType.Text; cmd.CommandText = "INSERT yorutablename(columnname) VALUES ('testvalue')"; cmd.Connection = sqlConnection1; sqlConnection1.Open(); cmd.ExecuteNonQuery(); sqlConnection1.Close();

    Hope it could help


    Cheers, Hemendra-MCTS "Yesterday is just a memory,Tomorrow we may never see"

    Monday, April 23, 2012 7:28 AM
    Moderator

All replies

  • Hi,

    Use the System.Data.SqlClient to insert / update/delete data into database. You can find lots of material with some googling. Here is some reference links for you

    http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqldataadapter.insertcommand.aspx

    http://msdn.microsoft.com/en-us/library/ms233812%28v=vs.80%29.aspx

    Hope it could help


    Cheers, Hemendra-MCTS "Yesterday is just a memory,Tomorrow we may never see"

    Monday, April 23, 2012 6:49 AM
    Moderator
  • Thanks for your reply

    but how to submit that form value in database..?


    computermaster

    Monday, April 23, 2012 7:12 AM
  • Above links are already having some sample code:

    First add System.Data in your project and add System.Data.SqlClient on your .cs file

    string con="user id=sa; password=; Data Source=your database server name; Initial Catalog=your database name";

    System.Data.SqlClient.SqlConnection sqlConnection1 = new System.Data.SqlClient.SqlConnection(con); System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand(); cmd.CommandType = System.Data.CommandType.Text; cmd.CommandText = "INSERT yorutablename(columnname) VALUES ('testvalue')"; cmd.Connection = sqlConnection1; sqlConnection1.Open(); cmd.ExecuteNonQuery(); sqlConnection1.Close();

    Hope it could help


    Cheers, Hemendra-MCTS "Yesterday is just a memory,Tomorrow we may never see"

    Monday, April 23, 2012 7:28 AM
    Moderator