How to retrieve the Identity (@@IDENTITY) of a record you just inserted into a table.
- by Edward Boyle
SELECT @@IDENTITY will retrive that last generated @@IDENTITY from the current connection.
int thisid = (int)cmd.ExecuteScalar("SELECT @@IDENTITY",conn);
If there is another write in another connection you do not have to worry. Again, @@IDENTITY will retrieve last generated @@IDENTITY from the current connection. Null if no @@IDENTITY…