Recordset-Getting the ID of a row inserted when the ID is IDENTITY/AUTOINCREMENT

Recordset-Getting the ID of a row inserted when the ID is IDENTITY/AUTOINCREMENT

Post by Dave Stienesse » Sat, 08 Nov 1997 04:00:00

Hi all-
We have table(s) defined with the ID as an autoincrement/identity field so
the database can manage creating new unique IDs--
We have recordsets that add rows (leaving out the ID to let the database
fill it in).  The problem is we need the ID of the record added so we can
setup values in related tables and, since we didn't add the ID, we have no
idea how to identify the added row.  

but how do we get this value in a CRecordset?

Help please


1. Getting the currently inserted record-id of a IDENTITY-Table


I need the DB-ID of that record, which I have currently inserted. The
is, that the DB sets the record-ID automaticly (the column has IDENTITY
and a lot of other clients are inserting records into the same table at the

After inserting the record, do the following commands

(1)     INSERT(....) VALUES(....)

returning the right DB-ID in sense of my case?? Or do I have to put the
commands into BEGIN TRAN and COMMIT TRAN commands?? If the last
one is a duty, I'm getting another problem, because MS SQL isn't able to
handle real nested transactions in the sense of the DB-theory. My nested
tranaction has the following structure seeing below:

(2)     BEGIN TRAN t1
                BEGIN TRAN t2
                COMMIT / ROLLBACK TRAN t2  <-- ok
        COMMIT / ROLLBACK TRAN t1 <--------------- error

The error occurs, because MS SQL overwites the transaction name t1. Has s
omeone an answer of one or of both problems?

Thanks in advance

Reiner Giesen

2. Enterprise Memory Usage

3. problem using JDBC proxy as applet

4. Getting last insert ID from an IDENTITY column

5. Paradox Linked server

6. Recordset.[id] vs Recordset![id] what is the difference


8. Create a trigger for autoincrement ID (NOT Identity)

9. Getting the new autoincrement id value

10. Autoincrement id for newly inserted records returns blank

11. Getting the value of an autoincrement or identity field during an sql insert