SQL update statement in C#

前端 未结 9 1611
陌清茗
陌清茗 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:22

    If you don't want to use the SQL syntax (which you are forced to), then switch to a framework like Entity Framework or Linq-to-SQL where you don't write the SQL statements yourself.

    0 讨论(0)
  • 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);  
    
    0 讨论(0)
  • 2020-11-27 05:28
    command.Text = "UPDATE Student 
      SET Address = @add, City = @cit
      Where FirstName = @fn and LastName = @add";
    

     

    0 讨论(0)
提交回复
热议问题