Groups | Blog | Home
all groups > c# > february 2005 >

c# : INSERT statemant return ID


Nick Malik [Microsoft]
2/19/2005 2:44:59 PM
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.
--
[quoted text, click to view]

Grei
2/19/2005 5:00:36 PM
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

Cor Ligthert
2/19/2005 5:13:36 PM
Grei,

I assume you are searching for this one.

@@identity
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/tsqlref/ts_globals_50u1.asp

I hope this helps?

Cor

Grei
2/19/2005 7:13:12 PM
Yes, that's exactyl what i was looking for, thanx!
But what about Access, i didn't find any answeres there.

[quoted text, click to view]

Cor Ligthert
2/19/2005 7:17:06 PM
Grei,

AFAIK is it the same,

Cor

AddThis Social Bookmark Button