Login | Register   
RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.


Disconnected Recordsets

One of the great and flexible features of the ADO recordset is that it can be disconnected from its data source, modified, and reconnected to update the data source. Here are the step-by-step instructions.




Building the Right Environment to Support AI, Machine Learning and Deep Learning

ne of the great and flexible features of the amazing elastic ADO recordset is that it can be disconnected from its data source, modified, and reconnected to update the data source. Once disconnected, it can be saved to disk or inserted into an email, and sent to another user. The second user can make changes and send it back to the first user, who can then open it from disk and update the data source. Here are the step-by-step instructions:

1. Open a client side recordset in UpdateBatch mode:

Dim rs as New ADODB.Recordset rs.CursorLocation=adUseClient rs.LockType= adLockBatchOptimistic rs.Open Source:="Select * From Authors", ActiveConnection:="Pubs" 'Pubs is an ODBC DSN

2. Disconnect the recordset by setting its ActiveConnection to Nothing. Don't close the connection. When a connection is closed it closes all associated recordsets.

Set rs.ActiveConnection = Nothing

3. Modify the data. Even though the recordset is disconnected from its data source, it is still fully functional. You can make changes to the data and save it using the Update method. All changes are stored in the recordset until the UpdateBatch method is called. The quickest way to display and modify the data is to place an instance of the Microsoft DataGrid 6.0 OLEDB (MSDATGRD.OCX) on a form and set its DataSource property to the recordset.

Set DataGrid1.DataSource=rs

4. Save the recordset to disk. Use the recordset's Save method. You can save it with any extension, I prefer .rs:

rs.Save "D:\Authors.rs"

5. Send the recordset file to another user via floppy disk or email. She can open it using the recordset's Open method with adCmdFile for the Options argument:

rs.Open Source:="D:\ Authors.rs", Options:=adCmdFile

6. The second user can modify the data and save changes back to the persisted file from which the recordset was opened by calling the recordset's Save method without specifying a filename.


7. The second user can send it back to the first user who can reconnect the recordset by setting it to a valid connection. If the recordset is already open then close it using the Close Method.

On Error Resume Next rs.Close On Error Goto 0 rs.ActiveConnection = "Pubs"

8. To update the data source with all the changes call the recordset's Updatebatch method.


Michael Gellis works at Flash Creative Management (a Microsoft Partner) as a Visual Basic developer. He is a Microsoft Certified Professional in VB5 and VB6 and is co-writing a book for Sybex on VB 6.0 and distributed applications. You can reach him here.
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date