Entity Framework and SCOPE_IDENTITY

前端 未结 3 1580
北海茫月
北海茫月 2021-01-21 22:09

I have a stored procedure that inserts into a table then executes this line

SET @returnVal = SCOPE_IDENTITY();

and after that I\'ve tried both:

3条回答
  •  既然无缘
    2021-01-21 22:48

    Declare a output type of parameter in your procedure definition:

     create procedure [dbo].[Procedurename] @returnVal int output
     as 
     SET @returnVal = SCOPE_IDENTITY();
    

    and while calling the stored procedure call it as:

     declare @returnVal int
     exec Procedurename @returnVal output
     print @returnVal 
    

提交回复
热议问题