A Brief History of Persistence in ADO

[Previous] [Next]

In ADO 2.0, the ADO development team added a Save method to the Recordset object so that you could write code that looks like this:

 strSQL = "SELECT * FROM Orders" rsOrders.CursorLocation = adUseClient rsOrders.Open strSQL, cnDatabase, adOpenStatic, _ adLockBatchOptimistic, adCmdText 'Disconnect from the database. Set rsOrders.ActiveConnection = Nothing 'Modify the data.  'Save the modifications and close the Recordset. rsOrders.Save strPathToFile, adPersistADTG rsOrders.Close 'At this point the user closes and reopens the application.  'Open the Recordset, reset the connection, and update the database. rsOrders.Open strPathToFile, , adOpenStatic, _ adLockBatchOptimistic, adCmdFile Set rsOrders.ActiveConnection = cnDatabase rsOrders.UpdateBatch 

This code performs the following actions:

  1. Retrieves data from the Orders table in the database
  2. Disconnects the Recordset object from the Connection object
  3. Modifies the data in the Recordset
  4. Saves the data to a file, and closes the Recordset
  5. Reopens the Recordset from the modified file
  6. Reassociates the Recordset with the Connection object
  7. Submits the pending changes to the database

Of course, you'd want to create separate code modules to group specific actions, but I think you get the idea: ADO saves you time by simplifying this potentially complex scenario.

In ADO 2.1, they added a second format for the data: eXtensible Markup Language (XML). Simply use the optional PersistFormat parameter on the Save method to store your data in XML format, as shown here:

 rsOrders.Save strPathToFile, adPersistXML 

Now how much would you pay? Don't answer yet. Just look what else you get! ADO 2.5 brings even more functionality to the Save method. No longer do you need to store your data in a file; you can now save the data in a stream. You can use the Save method with the new ADO Stream object or with the Response object, which is available through the Active Server Pages (ASP) object model. Implementation examples using the Stream and Response objects, respectively, are shown here:

 'Use the ADO Stream object with the Save method. Set stmData = New ADODB.Stream rsOrders.Save stmData, adPersistADTG 'Use the ASP Response object with the Save method. rsOrders.Save Response, adPersistADTG 



Programming ADO
Programming MicrosoftВ® ADO.NET 2.0 Core Reference
ISBN: B002ECEFQM
EAN: N/A
Year: 2000
Pages: 131
Authors: David Sceppa

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net