Accessing Deprecated Recordsets


When you upgrade to ADO 2.1 or 2.5 from an earlier version, you might discover that your old applications don't seem to work correctly. In some cases, you get unresolvable errors, especially when working with the Data Environment Designer, the ActiveX Data Control, or the Data Form Wizard All of these Visual Basic 6.0 tools were left behind when the MDAC team changed the interfaces (basically the structure) in the Recordset object.

While Visual Studio Service Pack 4 (SP4) is supposed to correct these Visual Basic 6.0 tool problems, you might have a need in your own applications to code around these changes. Well, you're in luck. ADO's type library includes "deprecated" interfaces for older versions of the Recordset object. These can be seen, along with other interesting behind-the-scenes interfaces, if you set the Visual Basic 6.0 Object Browser to show hidden members. Simply right-click on the object browser (click on View..Object Browser or press F2 to make it appear) and click "Show hidden members." Once set, the Recordset, Recordset15, Recordset20, and Recordset21 interfaces are all visible, as shown in Figure 7-7. To use these older (outdated) interfaces, declare your Recordset object as one of these deprecated interfaces.

click to expand
Figure 7-7: Right-click the Object Browser and select "Show hidden members" to see deprecated objects such as Recordset21.

Another use for deprecated Recordsets is the capability to marshal them to older clients. For example, if you have a client that's running ADO 2.0 and your server is running 2.5, you can send the client a Recordset20 deprecated Recordset. Here's an example of a routine that can be coded to return the ADO 1.5 version of the Recordset:

 Public Function ReturnRS(strConnect As String, _                         strQuery As String) As ADODB.Recordset15      ' Or, Use this syntax for ADO 2.0 or 2.5      ' Public Function ReturnRS(strConnect As String, _                          ' strQuery As String) As ADODB.[_Recordset15]        Dim adoCon1 As New ADODB.Connection        Dim adoRs1 As New ADODB.Recordset        ' Set the CursorLocation to adUseClient to return an ADORecordset.        adoCon1.CursorLocation = adUseClient        adoCon1.Open strConnect        adoRs1.Open strQuery, adoCon1, adOpenStatic, adLockBatchOptimistic        ' Cannot close the ADO Recordset object here, but it can be disassociated.        Set adoRs1.ActiveConnection = Nothing        ' Return ADO Recordset object to Client.        Set ReturnRS = adoRs1        adoCon1.Close End Function 


The code path used to implement the Recordset does not change when you choose a deprecated interface. This technique simply exposes the selected version's properties, methods, and events, and hides the full implementation.


ADO Examples and Best Practices
Ado Examples and Best Practices
ISBN: 189311516X
EAN: 2147483647
Year: 2000
Pages: 106

Similar book on Amazon © 2008-2017.
If you may any questions please contact us: