You can follow the below code. My code in C#
private void btnUpdate_Click(object sender, System.EventArgs e)
{
SqlConnection cn;
SqlCommand cmd ;
string strsql ;
try
{
cn = new SqlConnection("Server=localhost;uid=sa;pwd=;database=northwind;");
strsql = "Update Region set RegionDescription=@RegionDescription where RegionId=@RegionId"
cmd = new SqlCommand(strsql, cn);
cmd.Parameters.Add(new SqlParameter("@RegionId", SqlDbType.Int));
cmd.Parameters.Add(new SqlParameter("@RegionDescription", SqlDbType.NVarChar, 40));
cmd.Parameters["@RegionId"].Value = Convert.ToInt32(txtRegionID.Text);
cmd.Parameters["@RegionDescription"].Value = txtRegionDescription.Text;
cn.Open();
cmd.ExecuteNonQuery();
lblMessage.Text = "Updated Successfully";
}
catch (Exception ex)
{
lblMessage.Text = ex.Message;
lblMessage.ForeColor = Color.Red;
}
finally
{
cn.Close();
}
}
Thanks.