sql server update c 23 example code

Solutions on MaxInterview for sql server update c 23 example code by the best coders in the world

showing results for - "sql server update c 23 example code"
Moritz
13 Nov 2016
1string name = "test1";
2int id = 1;
3using (SqlConnection cnn = new SqlConnection("Server=localhost;Database=DEV;User Id=test;Password=test!@#$;Connect Timeout=5400"))
4{
5  cnn.Open();
6  string querystr = "UPDATE [dbo].[TABLE] SET [name]=@p_name WHERE [id]=@p_id";
7  using (var cmd = new SqlCommand(querystr, cnn))
8  {
9     //set value  
10     cmd.Parameters.AddWithValue("@p_name", name);
11     //where with id
12     cmd.Parameters.AddWithValue("@p_id", id);
13     int ret = cmd.ExecuteNonQuery();
14  }
15}