title: how to retrieve data from database into textbox and save the edited data from the same textbox to database
body: <p>i m working on a web application that stores user information, i want to get the userdetails from the database into textboxes where i can make changes to the data and use a button to store the data from the same text boxes to the same table of the database.it is like updating/ editing user profile
   so far i am able to get the data into textboxes but i am unable to update the data. the page submits the data but there is no change in the data base </p>
  
  <p>the  html &amp; code i am using is:</p>
  
  <pre><code>&lt;div id="pagebody" style="width: 80%; height: 120%; margin: auto;"&gt;
      &lt;div id="personalinfodiv" class="try" align="center" style="background-color: white; width: 80%; border: 1px solid gray; margin: auto"&gt;
          &lt;h3 align="center" &gt;Personal information&lt;/h3&gt;
          &lt;table&gt;
              &lt;tr&gt;&lt;td&gt;&lt;asp:Label ID="fname"  runat="server" Text="First Name  :" Font-Bold="true" ForeColor="GrayText"&gt;&lt;/asp:Label&gt;&lt;/td&gt;  &lt;td&gt;&lt;asp:TextBox cssClass="textbox1"  ID="firstnametext" runat="server"&gt;&lt;/asp:TextBox&gt;&lt;/td&gt;&lt;/tr&gt;
              &lt;tr&gt;&lt;td&gt;&lt;asp:Label ID="lname" runat="server" Text="Last Name  :" Font-Bold="true" ForeColor="GrayText"&gt;&lt;/asp:Label&gt;&lt;/td&gt;  &lt;td&gt;&lt;asp:TextBox cssClass="textbox1" ID="lastnametext" runat="server"&gt;&lt;/asp:TextBox&gt;&lt;/td&gt;&lt;/tr&gt;
              &lt;tr&gt;&lt;td&gt;&lt;asp:Label ID="gender" runat="server" Text="Gender  :" Font-Bold="true" ForeColor="GrayText"&gt;&lt;/asp:Label&gt;&lt;/td&gt;  &lt;td&gt;&lt;asp:DropDownList cssClass="textbox1" ID="gendertext" runat="server" DataSourceID="SqlDataSource1" DataTextField="Gender" DataValueField="Gender"&gt;&lt;asp:ListItem Text="Male" Value="1"&gt;&lt;/asp:ListItem&gt;&lt;asp:ListItem Text="Female" Value="2"&gt;&lt;/asp:ListItem&gt;&lt;/asp:DropDownList&gt;
                  &lt;asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="&lt;%$ ConnectionStrings:Koshur %&gt;" SelectCommand="SELECT [Gender] FROM [userdetails] WHERE ([Username] = @Username)"&gt;
                      &lt;SelectParameters&gt;
                          &lt;asp:QueryStringParameter Name="Username" QueryStringField="user" Type="String" /&gt;
                      &lt;/SelectParameters&gt;
                  &lt;/asp:SqlDataSource&gt;
                  &lt;/td&gt;&lt;/tr&gt;
              &lt;tr&gt;&lt;td&gt;&lt;asp:Label ID="dob" runat="server" Text="Date of Birth  :" Font-Bold="true" ForeColor="GrayText"&gt;&lt;/asp:Label&gt;&lt;/td&gt;  &lt;td&gt;&lt;asp:TextBox cssClass="textbox1" ID="dobtext" runat="server"&gt;&lt;/asp:TextBox&gt;
                  &lt;/td&gt;&lt;/tr&gt;
              &lt;tr&gt;&lt;td&gt;&lt;asp:Label ID="Contactno" runat="server" Text="Contact No :" Font-Bold="true" ForeColor="GrayText"&gt;&lt;/asp:Label&gt;&lt;/td&gt;  &lt;td&gt;&lt;asp:TextBox cssClass="textbox1" ID="contacttext" runat="server"&gt;&lt;/asp:TextBox&gt;
  
                  &lt;/td&gt;&lt;/tr&gt;
          &lt;/table&gt;
  </code></pre>
  
  <p>C# for data retrieval :    </p>
  
  <pre><code>string CSs = ConfigurationManager.ConnectionStrings["Koshur"].ConnectionString;
  using (SqlConnection conn = new SqlConnection(CSs))
  {
      string query = "select * from userdetails where Username='" + HttpContext.Current.User.Identity.Name.ToString() + "';";
      SqlCommand cmd = new SqlCommand(query, conn);
      SqlDataAdapter da = new SqlDataAdapter(cmd);
      DataSet ds = new DataSet();
      da.Fill(ds, "userdetails");
      firstnametext.Text=ds.Tables["userdetails"].Rows[0]["Firstname"].ToString();
      lastnametext.Text = ds.Tables["userdetails"].Rows[0]["Lastname"].ToString();
      dobtext.Text = ds.Tables["userdetails"].Rows[0]["Dateofbirth"].ToString();
      contacttext.Text = ds.Tables["userdetails"].Rows[0]["ContactNO"].ToString();
  }
  </code></pre>
  
  <p>c# to update the data into table and
  i m using a stored procedure for this</p>
  
  <pre><code>protected void savecontinue_Click(object sender, EventArgs e)
  {
     // Response.Redirect("test.aspx?q=" + firstnametext.Text +"&amp;" + lastnametext.Text);
     string ct = ConfigurationManager.ConnectionStrings["Koshur"].ConnectionString;
     using (SqlConnection con = new SqlConnection(ct))
     {
         SqlCommand cmnd = new SqlCommand("spupdateuserprofiledetails", con);
         cmnd.CommandType = CommandType.StoredProcedure;
  
         SqlParameter first = new SqlParameter("@Firstname", firstnametext.Text);
         SqlParameter last =new SqlParameter("@Lastname", lastnametext.Text);
  
         SqlParameter dobb=new SqlParameter("@Dateofbirth", dobtext.Text);
         SqlParameter connt=new SqlParameter("@ContactNo", contacttext.Text);
         SqlParameter userna = new SqlParameter("@Username", HttpContext.Current.User.Identity.Name.ToString());
  
         cmnd.Parameters.Add(first);
         cmnd.Parameters.Add(last);
         cmnd.Parameters.Add(dobb);
         cmnd.Parameters.Add(connt);
         cmnd.Parameters.Add(userna);
  
         con.Open();
         cmnd.ExecuteNonQuery();
     }
  }
  }
  </code></pre>
  
  <p>this is my stored procedure </p>
  
  <pre><code>create proc spupdateuserprofiledetails
  @Firstname varchar(100),
  @Lastname Varchar(100),
  @Dateofbirth varchar(100),
  @ContactNo varchar(100),
  @Username varchar(100)
  as
  begin
  update Userdetails
  set Firstname=@Firstname,Lastname=@Lastname,Dateofbirth=@Dateofbirth,ContactNO=@ContactNo 
  where Username=@Username
  
  end
  </code></pre>