TableAdapter.Insert get newly insert record

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I would have expected to be able to find this easily, but I couldn't.

I am using the TableAdapter.Insert command to insert a record.
I would like to then get an ID field from that record after insertion.
How to I retreive the record just inserted?

Gregory McCallum
(e-mail address removed)
 
Gregory,

Is the ID auto-generated? If so, you should execute the following
command using the connection that you inserted the record on:

select @@identity

You have to make sure the connection isn't closed, otherwise, you will
lose the last generated identity.

If you have inserted multiple records, this will return the last
generated value. If a trigger has inserted records as a result of the
original insert, you will see the id of those records.

Hope this helps.
 

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

Back
Top