【发布时间】:2021-02-19 02:54:48
【问题描述】:
我目前正在处理在删除订单中的项目期间运行两个 SQL 查询。一个用于从订单表中删除项目,另一个用于更新不同表上的库存。这是我写的:
public int DeleteItem(int stockItemId)
{
using (SqlConnection connection = new SqlConnection(connectionString))
{
using (SqlCommand command =
new SqlCommand("DELETE FROM DBO.OrderItems WHERE stockItemId=@stockItemId sp_UpdateStockItemAmount @Id, 1", //sp_SelectStockItems, @Id, 1
connection))
{
command.Parameters.AddWithValue("@stockItemId", stockItemId);
command.Parameters.AddWithValue("@Id", stockItemId);
connection.Open();
int result = -1;
try
{
result = command.ExecuteNonQuery();
}
catch (Exception error)
{
Console.WriteLine("Error: " + error.Message.ToString());
}
return result;
}
}
}
目前,当我尝试通过按下按钮执行此操作时遇到以下错误:
Exception thrown: 'System.Data.SqlClient.SqlException' in System.Data.dll
Error: Incorrect syntax near 'sp_UpdateStockItemAmount'.
sp_UpdateStockItemAmount 是我需要使用的存储过程,可以将 1 添加到 instock 列或删除 1 个库存。
目前我不太确定自己做错了什么。
【问题讨论】: