title: how to update a record from the values taken from the text box fields
body: <p>I am making a list of records in a web form with edit and delete options.  I have retrieved the values in the text box fields for update. Now, when
  the user clicks the update button, the record is updated.</p>
  
  <p>How can I do it remaining on the same page or redirected to another page?  </p>
  
  <p>This is my code:</p>
  
  <pre><code>public partial class WebForm1 : System.Web.UI.Page
  {
    protected void Page_Load(object sender, EventArgs e)
    {
      if (!Page.IsPostBack)
      {
         binddata();
      }
   }
     SqlConnection con;
     SqlDataAdapter da;
     DataSet ds;
  
    void   binddata()
    {
     string pid = Request.QueryString["Prod_Id"];
     con = new SqlConnection("Data Source=.\\sqlexpress; initial catalog=PracticeDb; user id=sa; pwd=manager;");
      con.Open();
      da = new SqlDataAdapter("Select * from Products where Prod_Id='" + pid + "'", con);
      DataSet ds = new DataSet();
      da.Fill(ds);
      con.Close();
  
     string  P_Name = ds.Tables[0].Rows[0]["Prod_Name"].ToString();
     string U_Prce = ds.Tables[0].Rows[0]["Unit_Price"].ToString();
     string I_Hnd = ds.Tables[0].Rows[0]["In_Hand"].ToString();
     string Fxd = ds.Tables[0].Rows[0]["Fixed"].ToString();
     string Stus = ds.Tables[0].Rows[0]["Status"].ToString();
  
     TextBox1.Text = P_Name;
     TextBox2.Text = U_Prce;
     TextBox3.Text = I_Hnd;
     TextBox4.Text = Fxd;
     TextBox5.Text = Stus;
   }
  
   protected void Unnamed1_Click(object sender, EventArgs e)
   {                  
     string pid = Request.QueryString["Prod_Id"];
     var Pd_nme = TextBox1.Text;
     decimal Uni_prce = decimal.Parse(TextBox2.Text);
     int In_hnd = int.Parse(TextBox3.Text);
     string Fxd = TextBox4.Text;
     string Stus = TextBox5.Text;
     SqlConnection con = new SqlConnection();
     con.ConnectionString = ("Data Source=.\\sqlexpress; initial catalog=PracticeDb; user id=sa; pwd=manager;");
      con.Open();
      string qry = "UPDATE PRODUCTS SET Prod_Name='" + Pd_nme + "',Unit_Price='" + Uni_prce + "',In_Hand='" + In_hnd + "',Fixed='" + Fxd + "',Status='" + Stus + "' where Prod_Id='" + pid + "'";
      SqlCommand cmd = new SqlCommand(qry, con);
      cmd.ExecuteNonQuery();
      con.Close();                   
   }
  }
  }
  </code></pre>
  
  <p>Thanks.</p>