sql server update c# example code
Example: sql server update c# example code
string name = "test1";
int id = 1;
using (SqlConnection cnn = new SqlConnection("Server=localhost;Database=DEV;User Id=test;Password=test!@#$;Connect Timeout=5400"))
{
cnn.Open();
string querystr = "UPDATE [dbo].[TABLE] SET [name]=@p_name WHERE [id]=@p_id";
using (var cmd = new SqlCommand(querystr, cnn))
{
//set value
cmd.Parameters.AddWithValue("@p_name", name);
//where with id
cmd.Parameters.AddWithValue("@p_id", id);
int ret = cmd.ExecuteNonQuery();
}
}