简体   繁体   中英

Getting the error in passing parameter to a stored procedure

I have the following stored procedure:

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
);

When I am running the program I am getting the following error:

procedure or function sp_insertHashBin expects parameter @Seqno which was not supplied

But I am passing 4 parameters to procedure

There is your problem: sp_InsertHashBinMinHash expects 5 parameters ( Id , HashBin , HashTable , SubFingerprintId and Seqno ). You are only calling it with 4. So one is missing.

I would rewrite it as

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

And, passing values to your procedure from C#, add parameter @Id with proper Direction property.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM