【发布时间】: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