Re: SqlCommand which INSERTS and then SELECTs single value
- From: Edward Diener <ediener@xxxxxxxxxxxxxxxxxx>
- Date: Thu, 22 Jun 2006 09:02:13 -0400
Kerry Moorman wrote:
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.
Thanks for the information and shorter version of retrieving the identity I have just inserted.
.
Kerry Moorman
"Edward Diener" wrote:
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 ExecuteScalar call work correctly with such an Sql command ?
- References:
- SqlCommand which INSERTS and then SELECTs single value
- From: Edward Diener
- SqlCommand which INSERTS and then SELECTs single value
- Prev by Date: Reading and writing to DataTable question
- Next by Date: Re: Connection to ORACLE: Need some explanations
- Previous by thread: SqlCommand which INSERTS and then SELECTs single value
- Next by thread: Retrieving output params from stored procedure?
- Index(es):
Relevant Pages
|