I've been trying to find a similar question but couldn't find one so forgive me if this has already been dealt with.
Is there a way that I can immediately obtain the value of an auto incrementing identity field in SQL if I insert a new record?
Let's say I run the following command:
SqlCommand myCommand = new SqlCommand("INSERT INTO Users (UserName, Age) VALUES ('Joe Bloggs', 30)", myConnection);
Users table has an auto incrementing identity field called
UserID. Is there a way I can obtain the new value of UserID without having to run a subsequent
SELECT UserID FROM Users WHERE... query?