【问题标题】:Stored procedure parameter was not supplied error未提供存储过程参数错误
【发布时间】:2012-05-06 14:44:41
【问题描述】:

我的 SQL Server 存储过程有问题。虽然我提供了参数,虽然参数不为空,但我得到了“未提供参数”错误

我的 C# 代码在这里:

staffInfo.DeleteCommand = "deleteStaff";
staffInfo.DeleteCommandType = SqlDataSourceCommandType.StoredProcedure;
staffInfo.DeleteParameters.Add("tcId", stafftc);
staffInfo.Delete();

存储过程:

ALTER PROCEDURE dbo.deleteStaff 
(
    @tcId varchar(11)
)
AS
BEGIN
    DECLARE @memId int;
SELECT @memId = staffId FROM staff WHERE TCid = @tcId;
DELETE FROM member WHERE memId = @memId;
END

删除操作完美完成。但我还是得到了这个错误。你有什么建议?

【问题讨论】:

  • 在 MSDN 中有一条关于错误“未提供参数”Make sure that no BoundField controls in the data-bound control that you bind to the SqlDataSource control have names that match any parameter names in the DeleteParameters collection. Parameters that have the same name as bound fields are excluded from the SQL command, and a "parameter was not supplied" error might result. 的注释可能是这种情况吗?
  • 不,它也没有用。结果,我删除了该过程,并尝试通过查询处理执行。它有效,然后我继续我的方式。
  • 为什么不使用 sql server profiler 并检查发送执行的查询?可能会得到一些信息
  • 参数不是必须以@为前缀吗?
  • 没有 DBM,它没有。分配存储过程参数时,不会在开头使用“@”符号。如果这样做,它将给出与此示例完全相同的错误。

标签: c# sql-server stored-procedures parameters


【解决方案1】:

如果删除操作成功,我可以想象发生这种情况的唯一方法(特别是因为您没有提供异常的详细信息)是可能有一个删除触发器正在调用另一个失败的存储过程.

【讨论】:

  • 这是一个非常有意义的答案。但是没有触发,只有级联。当成员表中的一行被删除时,其他 3 个表也会受到影响。但是,相关行也会被删除。
  • 那些 child 表上的任何删除触发器?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-02-27
  • 1970-01-01
  • 1970-01-01
  • 2017-09-15
  • 1970-01-01
  • 2021-07-14
相关资源
最近更新 更多