PC Review
Forums
Newsgroups
Microsoft DotNet
Microsoft ADO .NET
SqlCommand which INSERTS and then SELECTs single value
Forums
Newsgroups
Microsoft DotNet
Microsoft ADO .NET
SqlCommand which INSERTS and then SELECTs single value
![]() |
SqlCommand which INSERTS and then SELECTs single value |
|
|
Thread Tools | Rate Thread |
|
|
#1 |
|
Guest
Posts: n/a
|
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 ? |
|
|
|
#2 |
|
Guest
Posts: n/a
|
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 "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 ? > |
|
|
|
#3 |
|
Guest
Posts: n/a
|
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 ? >> |
|
![]() |
|
| Thread Tools | |
| Rate This Thread | |
|
|

Main Page 

