这是我的代码:
string cmdstr = "UPDATE itemsordered i " +
"INNER JOIN"+
"( SELECT itemsOrdered_quantity, itemsOrdered_ID, "+
"IF itemsOrdered_quantity = '"+quantityTxtBox.Text+"' SELECT 'EQUAL' "+
"IF itemsOrdered_quantity < '" + quantityTxtBox.Text + "' SELECT 'LESS' " +
"IF itemsOrdered_quantity > '" + quantityTxtBox.Text + "' SELECT 'MORE' " +
"END AS r "+
"FROM itemsordered "+
") res ON i.itemsOrdered_ID = res.itemsOrdered_ID "+
"INNER JOIN stocksdb s ON s.stock_ID = i.stock_ID " +
"SET s.stock_quantity = (s.stock_quantity + i.itemsOrdered_quantity), " +
"s.stock_dateUpdated = '" + DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss") + "', " +
"i.itemsOrdered_status = 'RECEIVED', " +
"i.itemsOrdered_dateReceived = '" + DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss") + "'" +
"WHERE i.itemsOrdered_ID = '" + idTxtBox.Text + "' AND res.r = 'EQUAL'";
cmd = new MySqlCommand(cmdstr, db.mycon);
cmd.ExecuteNonQuery();
MessageBox.Show("ITEM RESTOCKED!");
我真正想做的是,如果itemsOrdered_quantity
等于 中的值,quantityTxtBox
那么它将s.stock_quantity
通过将 上的金额添加itemsOrdered_quantity
到当前金额来更新 。
我还想制作其他 IF 子句。但我想先解决这个难题。
它返回一个错误cmd.ExecuteNonQuery
并指向我的 SQL 字符串“靠近”我的 IF 语句。