How to use UPDATE in ado net

后端 未结 1 1062
长情又很酷
长情又很酷 2021-01-12 09:56

I need to perform an update in a table(Homework). But it is not just replacing an old value with a new one; to the already existing value in the column i have to add(SUM) th

相关标签:
1条回答
  • 2021-01-12 10:19

    If i understand you correctly (i'm not sure i do) you want something like this:

    string sql2 = "UPDATE student SET moneyspent = moneyspent + @spent WHERE id=@id";
    SqlCommand myCommand2 = new SqlCommand(sql2, conn);
    myCommand2.Parameters.AddWithValue("@spent", 50 )
    myCommand2.Parameters.AddWithValue("@id", 1 )
    

    Notice how i've used parameters and not string concatenation, very important!!

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