@@IDENTITY after INSERT statement always returns 0

后端 未结 13 1350
一整个雨季
一整个雨季 2021-01-11 13:00

I need a function which executes an INSERT statement on a database and returns the Auto_Increment primary key. I have the following C# code but, while the INSERT statement w

13条回答
  •  梦谈多话
    2021-01-11 13:26

    I think that @@identity is valid only in the scope of the command - in your case when you execute "statement".

    Modify your "statement"so that the stored procedure itself will return the @@IDENTITY value right after the INSERT statement, and read it as the return code of the stored procedure execution.

提交回复
热议问题