How do i get SCOPE_IDENTITY from INSERT query using tableadapter.

G

Guest

Hi,
I have a table adapter for a database with an insert query. I want to be
able to get the PRIMARY key of the inserted record for that insert statement.
I know that SCOPE_IDENTITY is the database equivalent. How do i get that
value from an InsertQuery call from TableAdapter generated by VS.NET?
 
M

Mattias Sjögren

I have a table adapter for a database with an insert query. I want to be
able to get the PRIMARY key of the inserted record for that insert statement.
I know that SCOPE_IDENTITY is the database equivalent. How do i get that
value from an InsertQuery call from TableAdapter generated by VS.NET?

Add SELECT SCOPE_IDENTITY() to the end of the query, and change its
execution mode from NonQuery to Scalar. There's a pretty good guide
here

http://msdn2.microsoft.com/en-us/library/aa581778.aspx

If you're calling a stored procedure to do the insert, return the
identity with an out parameter of with the return value.

http://blogs.msdn.com/smartclientdata/archive/2006/08/09/693113.aspx


Mattias
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top