c# .net操作必须使用可更新查询
本文关键字:可更新 查询 net 操作 | 更新日期: 2023-09-27 18:01:19
cmd3.ExecuteNonQuery();
for(int i=0; i<listView1.Items.Count;i++)
{
string query2 = "INSERT INTO OrderItems(Order_ID,Item_ID,OI_Quantity,Unit_Price) values ('"+Convert.ToInt32(textBoxId.Text)+"','"+Convert.ToInt32(this.listView1.Items[i].SubItems[5].Text.ToString())+"','"+Convert.ToInt32(this.listView1.Items[i].SubItems[3].Text.ToString())+"','"+Convert.ToInt32(this.listView1.Items[i].SubItems[2].Text.ToString())+"')";
OleDbCommand cmd2= new OleDbCommand(query2,con);
cmd2.ExecuteNonQuery();
string query3 = "UPDATE Item set stock=(select stock from Item where ID='" + Convert.ToInt32(this.listView1.Items[i].SubItems[5].Text.ToString()) + "') - '" + Convert.ToInt32(this.listView1.Items[i].SubItems[3].Text.ToString()) + "' where ID='" + Convert.ToInt32(this.listView1.Items[i].SubItems[5].Text.ToString()) + "' ";
OleDbCommand cmd3 = new OleDbCommand(query3, con);
cmd3.ExecuteNonQuery();
}
在更新查询中执行减号操作,其中参数以"引号为界,sql不将其作为整数。
您可以将减号操作的结果存储在变量中,然后在更新查询中使用该变量