SQL update statement in C#

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

    Please, never use this concat form:

    String st = "UPDATE supplier SET supplier_id = " + textBox1.Text + ", supplier_name = " + textBox2.Text
            + "WHERE supplier_id = " + textBox1.Text;
    

    use:

    command.Parameters.AddWithValue("@attribute", value);
    

    Always work object oriented

    Edit: This is because when you parameterize your updates it helps prevent SQL injection.

提交回复
热议问题