Getting return value from stored procedure in ADO.NET

前端 未结 5 1508
感动是毒
感动是毒 2020-12-09 03:43

I know that there is another question with nearly the same title, but it doesn\'t answer my question. I have a stored procedure, which returns the unique identifier after in

5条回答
  •  离开以前
    2020-12-09 04:44

    Do you get the value of you EXEC in TSQL? I wonder if refactoring the TSQL would help (and using SCOPE_IDENTITY():

    so change:

    COMMIT TRAN T1
    RETURN @@IDENTITY
    

    to:

    SET @auctionID = SCOPE_IDENTITY()
    COMMIT TRAN T1
    RETURN @auctionID
    

    (I would also change the other @@IDENTITY to SCOPE_IDENTITY())


    As a minor optimisation, you could also use:

    return (int)retval.Value;
    

    but this side of things should have worked "as is" from what I can see (hence why I'm focusing on the TSQL).

提交回复
热议问题