微软官方文档提供了一个删除记录的示例:
// Create the DeleteCommand.
command = new SqlCommand(
"DELETE FROM Customers WHERE CustomerID = @CustomerID", connection);
// Add the parameters for the DeleteCommand.
parameter = command.Parameters.Add(
"@CustomerID", SqlDbType.NChar, 5, "CustomerID");
parameter.SourceVersion = DataRowVersion.Original;
adapter.DeleteCommand = command;
但是在我的系统上不起作用(抱怨缺少@CustomerID)。如果我替换为
command.Parameters.Add("@CustomerID", SqlDbType.NChar, 5, "CustomerID");
以上使用 < /p > 标签。
command.Parameters.AddWithValue("@CustomerID", 5);
它有效。
为什么?