Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


advertisement
 

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.


advertisement
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.

rs.Save

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.

rs.UpdateBatch





   
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.

 

 

Sitemap