为什么没能正常执行,字段值没有变化,也没有显示任何错误,代码如下:
for (int kc = 0; kc < dataGridView2.RowCount; kc++)

                             //更新库存表数据
       SqlCommand cmdupdatekucun = new SqlCommand("update kucun_shangpin set shuliang=shuliang - '" + Convert.ToDouble(this.dataGridView2.Rows[kc].Cells[9].Value) + "' where sp_id='" + this.dataGridView2.Rows[kc].Cells[1].Value + "'", conyewu);
        cmdupdatekucun.ExecuteNonQuery();  }

解决方案 »

  1.   

    断点调试,看看sql语句是什么?
    然后拷到sql分析器去执行下
      

  2.   

    SqlCommand cmdupdatekucun = new SqlCommand("update kucun_shangpin set shuliang=shuliang - " + Convert.ToDouble(this.dataGridView2.Rows[kc].Cells[9].Value) + " where sp_id='" + this.dataGridView2.Rows[kc].Cells[1].Value + "'", conyewu);去掉引号试试的
      

  3.   


    SqlCommand cmdupdatekucun = new SqlCommand("update kucun_shangpin set shuliang='" + (shuliang - Convert.ToDouble(this.dataGridView2.Rows[kc].Cells[9].Value)) + "' where sp_id='" + this.dataGridView2.Rows[kc].Cells[1].Value + "'", conyewu);
    如果shuliang是int就不加单引号
    sp_id也是
      

  4.   


    提示“当前上下文中不存在名称shuliang”
      

  5.   

     SqlCommand cmdupdatekucun = new SqlCommand("update kucun_shangpin set shuliang=shuliang - '" + Convert.ToDouble(this.dataGridView2.Rows[kc].Cells[9].Value) + "' where sp_id='" + this.dataGridView2.Rows[kc].Cells[1].Value.tostring() + "'", conyewu);不需要去掉单引号。估计是sp_id没有转化为string,用我上面代码试试。