persisting autoincrement IDs 
Author Message
 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



Tue, 24 Jun 2003 23:38:16 GMT  
 persisting autoincrement IDs
Hi,

Retrieving the new record ID is not longer so simple under ADO then under
DAO. Try to work arround with an own created unique key.

Frank.



Tue, 24 Jun 2003 23:49:18 GMT  
 persisting autoincrement IDs
Well...yeah...I could use an API call to create GUIDs in the middle layer, but
that's not my point, and defeats the purpose of having a fully encapsulated
data access layer. The method returns the correct incremented ID when the table
index does not include an autoincremnt field, but fails when it does. I'm
trying to find out why, and how I can make it work in both situations.

Scott



Wed, 25 Jun 2003 03:56:29 GMT  
 persisting autoincrement IDs
If you use Access 2000 database then:

dim rs1 as New Recordset

SaveData = rs.Fields(0)

Resync - only for server cursor location method

Happy New Millenium!


Quote:
> 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



Wed, 25 Jun 2003 18:55:39 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Disabling Outlook 2000 Menu Items - Finding Control ID, IDs, ID's

2. How to extract ContactItem entry id from the AddressEntry entry id

3. Command IDs or CommandbarButton IDs

4. Command IDs or CommandbarButton IDs

5. HOWTO Sort ListView ID Column as if the ID were a NUMBER not STRING

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

7. Program ID vs. Task ID

8. Control process ID and Thread ID

9. HELP: Machine-ID or/and HDD-ID

10. SQL login ID versus user ID

11. Retain Class ID and Interface ID of ActiveX dll created in Visual Basic

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

 

 
Powered by phpBB® Forum Software