SQL update statement in C#

前端 未结 9 1650
陌清茗
陌清茗 2020-11-27 04:26

I have table \"Student\"

   P_ID   LastName  FirstName  Address  City

   1        Hansen    Ola                
   2        Svendson   Tov         


        
9条回答
  •  醉梦人生
    2020-11-27 05:28

    I dont want to use like this

    That is the syntax for Update statement in SQL, you have to use that syntax otherwise you will get the exception.

    command.Text = "UPDATE Student SET Address = @add, City = @cit Where FirstName = @fn AND LastName = @ln";
    

    and then add your parameters accordingly.

    command.Parameters.AddWithValue("@ln", lastName);
    command.Parameters.AddWithValue("@fn", firstName);
    command.Parameters.AddWithValue("@add", address);
    command.Parameters.AddWithValue("@cit", city);  
    

提交回复
热议问题