The information in this article applies to:
SUMMARYADO 2.1 can greatly simplify the process of retrieving identity or auto-increment fields into client-side recordsets. This article is designed to help you understand how this feature works and decide if it's right for you. MORE INFORMATION
Retrieving new values for auto-increment fields has been a complex and confusing task in past versions of ADO. You generally needed to use a server-side dynamic cursor in order to determine the value of the auto-increment field generated for your new row. You can learn more about this in Microsoft Knowledge Base Article: Q195910 INFO: Identity (AutoIncrement) Columns in ADO or RDS"/>ADO 2.1 simplifies this process to the point where the new auto-increment value appears to be retrieved "auto-magically" in a client-side cursor. It's important to understand how ADO attempts to retrieve this information in order to determine if this functionality will work properly with your particular scenario. When you add a new row to a client-side recordset in ADO through the AddNew and Update methods, ADO generates a query to insert that new row into your database. The query looks something like:
ADO then passes this query along to the OLE DB provider and it's up to the OLE DB provider or the back-end database to actually insert the new row into the table.Prior to ADO 2.1, this was the end of the work done by ADO in this case. ADO did not attempt to retrieve the value of the auto-increment field for the newly-created row in the table. Many database programmers with SQL Server experience might remember that SQL Server supported a query to retrieve such data, SELECT @@identity. The Jet OLE DB provider (as of version 4.0) now supports the same query. For additional information, please see the following article in the Microsoft Knowledge Base: Q232144 INFO: Jet OLE DB Provider Version 4.0 Supports SELECT @@IdentityThis query retrieves the last auto-increment value generated on a particular connection. There are two things to keep in mind:
Keep in mind that this feature relies on the underlying OLE DB provider or ODBC driver. If you're using any of the following scenarios, your client-side recordset will successfully retrieve the new auto-increment value:
Also remember that if your client-side recordset uses a LockType of adLockBatchOptimistic, you will not see the newly-generated auto-increment values until you call the UpdateBatch method. © Microsoft Corporation 1999, All Rights Reserved. Additional query words: Identity AutoIncrement
Keywords : kbADO kbDatabase kbJET kbMDAC kbOLEDB210 kbGrpVBDB kbGrpMDAC |
Last Reviewed: June 22, 1999 © 2000 Microsoft Corporation. All rights reserved. Terms of Use. |