Groups | Blog | Home
all groups > dotnet ado.net > june 2006 >

dotnet ado.net : SqlCommand which INSERTS and then SELECTs single value


Kerry Moorman
6/21/2006 1:33:02 PM
Edward,

The Select statement to retrieve the Identity column can just be:

SELECT SCOPE_IDENTITY()

You can append it to the INSERT statement separated by a semi-colon and use
ExecuteScalar to execute the INSERT and retrieve the new Identity.

Kerry Moorman


[quoted text, click to view]
Edward Diener
6/21/2006 2:52:40 PM
I want to do an SqlCommand which INSERTs a row with an Identity column
and then SELECTs the single identity column with a SELECT ID from
MyTable where ID = SCOPE_IDENTITY(). The CommandText consists of the
INSERT followed by and separated by a ; from the SELECT. Does using the
Edward Diener
6/22/2006 9:02:13 AM
[quoted text, click to view]

Thanks for the information and shorter version of retrieving the
identity I have just inserted.

[quoted text, click to view]
AddThis Social Bookmark Button