错误c#.net操作必须使用可更新的查询

时间:2021-08-17 15:36:51

Error is there in cmd3.ExecuteNonQuery();

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();
}

1 个解决方案

#1


0  

You are performing minus operation with in update query where parameters are bounded in '' quotes, which sql doesn't take as integer.

您正在使用更新查询执行减运算,其中参数以''引号为界,sql不作为整数。

You can store result of minus operation in a variable and then use that variable in update query.

您可以将减运操作的结果存储在变量中,然后在更新查询中使用该变量。

#1


0  

You are performing minus operation with in update query where parameters are bounded in '' quotes, which sql doesn't take as integer.

您正在使用更新查询执行减运算,其中参数以''引号为界,sql不作为整数。

You can store result of minus operation in a variable and then use that variable in update query.

您可以将减运操作的结果存储在变量中,然后在更新查询中使用该变量。