@@IDENTITY after INSERT statement always returns 0

后端 未结 13 1311
一整个雨季
一整个雨季 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条回答
  •  梦毁少年i
    2021-01-11 13:19

    You are using Jet (not SQL Server) and Jet can only handle one SQL statement per command, therefore you need to execute SELECT @@IDENTITY in a separate command, obviously ensuring it uses the same connection as the INSERT.

提交回复
热议问题