Answers for "how to update sql in c#."

SQL
1

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();
  }
}
Posted by: Guest on January-08-2021

Code answers related to "SQL"

Browse Popular Code Answers by Language