sql 更新update 加法运算

简单写法: 


sql_更新update_加法运算



update huiyuan set 金额 = 金额 + '100' where 单位 = '人社局'




正确写法:


        string con = ConfigurationManager.ConnectionStrings["sql"].ConnectionString;

        SqlConnection conn = new SqlConnection(con);
        conn.Open();

        string sql1 = "update 综合评议表 set " + TextBox4.Text + "=" + TextBox4.Text + "+1" + " where id =1";
        SqlCommand com1 = new SqlCommand(sql1, conn);

        int count1 = com1.ExecuteNonQuery(); //这里是执行 不要再错了 以前都是执行2此  难怪




/////////////////////////////

如果数量是 自定义的   用下面这个


        string sql1 = "update shangpin set 销量 = 销量 + " + shuliang.Text + " where id = '" + chaxunid.Text + "'";





winform代码
桂ICP备16004754号