INSERT statemant return ID

  • Thread starter Thread starter Grei
  • Start date Start date
G

Grei

i need RecordId of newly created record after i:
command.executenonquery(INSERT ....)

now i do:
INSERT, and later
SELECT max(RecordId)
but i'm hoping there is a better way.


is it possible in both Access and SQL server?

Thank you
 
Yes, that's exactyl what i was looking for, thanx!
But what about Access, i didn't find any answeres there.
 
The best way to make this work in both Access and SQL Server is to use GUID
keys, not identity columns.

Your app creates the GUID key, and inserts the record. There is no need to
get the database to return the value... you already have it.

--
--- Nick Malik [Microsoft]
MCSD, CFPS, Certified Scrummaster
http://blogs.msdn.com/nickmalik

Disclaimer: Opinions expressed in this forum are my own, and not
representative of my employer.
I do not answer questions on behalf of my employer. I'm just a
programmer helping programmers.
 

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