|
Correction... and clarification on @@identity usage Posted: 7 Feb 2004
I didn't mean to confuse anyone with my previous post. While stored procedures are available in Access 2000 and above, they can only be created using ADO and the Jet engine, and are invisible from the Access interface; considering there is no real performance gain between a stored procedure and a stored query, there really is no reason to use this capability.
One issue that keeps surfacing when inserting a record through ADO (in ASP/.NET or otherwise), is the apparent difficulty in obtaining the newly created record's key ID - if there is an autoinc field in the table being worked on.
After running some real tests, I finally figured out how to reliably obtain this ID from the database.
From MS Access, create a new query, and save it as Get_KeyID , paste this statement in the SQL view :
SELECT @@IDENTITY AS KeyID;
You can call this stored query right after performing an insert query (stored or not), but it has to use the same ADO connection in order to work and return the ID in question; if the connection is closed between the 2 calls, or a new connection established, it will return 0.
Hope this helped.
** Better burn bright than fade away ***
|