
persisting autoincrement IDs
In a generic database class, I have a "SaveData" method which takes a
disconnected recordset as an argument. Then:
Set rs = new ADODB.Recordset
with rs
.CursorLocation = adUseClient
.CursorType = adOpenKeyset
.LockType = adLockBatchOptimistic
end with
mConn.Open
set rs.activeconnection = mConn
with rs
.Open disRS
.UpdateBatch
End with
This works fine. The problem occurs when I try to retrieve the newly created
Autoincrement ID.
If the the index for the table does NOT include the Autoincrement field, then
this code works fine:
rs.Resync
SaveData = rs.Fields("ID").Value
If the index DOES include the ID field, Resync cause the error "row changed or
deleted at the data store". Plus, without doing the Resync, the ID field shows
0 in rs.
I'm using ADO 2.5 with the Jet 4.0 provider to access Access databases built
with VisData in VB6. It was my understanding that the 4.0 provider was supposed
to fix this inability to retrieve the new ID.
Anybody help me here?
Scott