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
you need to return the identity at the same time as you open the initial connection. Return a result set from your insert or an output variable.
You should also always use SCOPE_IDENTITY() not @@identity. Reference here
You should add
SELECT SCOPE_IDENTITY()
After the insert.