Freetutes.com

VB6 beginners tutorial - Learn VB6

Advanced VB6 tutorial - Learn Advanced VB6

VB .NET - Learn Visual Basic .NET

Systems Analysis - System analysis and Design tutorial for Software Engineering


You are here: Visual Basic > Advanced VB6 tutorial > Chapter 8

Disconnected Recordsets - Visual Basic 6 (VB6)

A disconnected Recordset object gets data from the server, but then goes offline to manipulate the data and reconnects to write the changes back to the server.

Such Recordsets must, of course, be implemented with client-side cursors.

They begin life connected to a Connection object. After the connection is made to the server and the Recordset retrieves its rows from the server, however, you can disconnect the Recordset from the Connection object and drop the Connection to the server entirely.

Your process or the user can then manipulate the Recordset completely offline.

If and when your application decides to update the server data with the offline changes, you can reconnect to a Connection object and send the changes to the server database.

You must take the following steps in code to implement a disconnected Recordset:

STEP BY STEP
8.8 Implementing a Disconnected Recordset

  1. Create a Recordset object with its CursorLocation property set to ClientSide.

  2. Connect the Recordset to a Connection object with the Open method.

  3. After you have retrieved rows into the Recordset, set the Recordset's ActiveConnection property to Nothing and close the Connection object. The Recordset is now disconnected.

  4. Manipulate the data in the Recordset through user edits and/or your own processing logic.

  5. When local processing is done, you can reestablish the Recordset's connection to the server by re-opening the Connection object and reconnecting the Recordset to the Connection object.

Listing 8.13 gives an example of code that implements a disconnected Recordset with offline processing.

LISTING 8.13
CODE THAT IMPLEMENTS A DISCONNECTED RECORDSET 'OPEN AN ADO CONNECTION

Dim connPubs As ADODB.Connection
Dim sConnString As String
sConnString = "Provider=MSDASQL.1;Data
Source=TRASH1006;Initial Catalog=pubs"
Set connPubs = New ADODB.Connection
connPubs.ConnectionString = sConnString
connPubs.Open
'OPEN A RECORDSET FROM THE CONNECTION
'BUT THEN DESTROY THE CONNECTION
Dim rs As ADODB.Recordset

LISTING 8.13
CODE THAT IMPLEMENTS A DISCONNECTED RECORDSET

Set rs = New ADODB.Recordset
With rs
' Specify the cursor's location
.CursorLocation = adUseClient
.LockType = adLockBatchOptimistic
.Source = "Select * from authors"
Set .ActiveConnection = connPubs
.Open
.ActiveConnection = Nothing
End With
connPubs.Close
Set connPubs = Nothing
'DO SOME PROCESSING TO THE DISCONNECTED
'RECORDSET
'........
'RE-OPEN AN ADO CONNECTION
Set connPubs = New ADODB.Connection
connPubs.ConnectionString = sConnString
connPubs.Open
'CONNECT THE RECORDSET TO THE CONNECTION
Set rs.ActiveConnection = connPubs
'UPDATE THE CONNECTION WITH THE RECORDSET'S
'CHANGES
rs.UpdateBatch
'AND ONCE AGAIN DESTROY THE CONNECTION
connPubs.Close
Set connPubs = Nothing

See Also


  

<< Previous | Contents | Next >>

Home | About Us | Privacy Policy | Contact Us

Copyright © Freetutes.com | All Rights Reserved