将参数传递给存储过程时出错

时间:2013-10-04 08:26:28

标签: c# sql-server stored-procedures

我有以下存储过程:

ALTER PROCEDURE sp_InsertHashBinMinHash
    @Id INT,
    @HashBin BIGINT,
    @HashTable INT,
    @SubFingerprintId BIGINT,
    @Seqno INT
AS

INSERT INTO HashBinsMinHash (
    HashBin,
    HashTable,
    Seqno,
    SubFingerprintId
    ) OUTPUT inserted.Id
VALUES
(
    @HashBin, @HashTable, @Seqno, @SubFingerprintId
);

当我运行程序时,我收到以下错误:

  

过程或函数sp_insertHashBin需要未提供的参数@Seqno

但我将4个参数传递给程序

2 个答案:

答案 0 :(得分:0)

有问题:sp_InsertHashBinMinHash需要5个参数(IdHashBinHashTableSubFingerprintIdSeqno)。你只用4来调用它。所以缺少一个。

答案 1 :(得分:0)

我会把它重写为

ALTER PROCEDURE sp_InsertHashBinMinHash
    @HashBin BIGINT,
    @HashTable INT,
    @SubFingerprintId BIGINT,
    @Seqno INT,
    @Id INT OUT
AS
BEGIN
INSERT INTO HashBinsMinHash (
    HashBin,
    HashTable,
    Seqno,
    SubFingerprintId
    ) 
VALUES
(
    @HashBin, @HashTable, @Seqno, @SubFingerprintId
);

set @Id = SCOPE_IDENTITY();
select @id
END

并且,从C#向您的过程传递值,添加带有正确Direction属性的参数@Id。