The ADO documentation states that an ADO record can
represent a row in a Recordset. However, the underlying OLE DB provider must
support the ADO Record object. For example, the Microsoft OLE DB Provider for
Internet Publishing supports the ADO Record object.
Steps to Reproduce Behavior
This sample uses the NWind.mdb database that comes with Visual
Basic.
- In Visual Basic, create a new Standard EXE project.
Form1 is created by default. - Add a two Command buttons to Form1.
Command1 and
Command2 are created by default. - From the Project menu, select References. In the References dialog box select the Microsoft ActiveX Data Objects
Library.
- Paste the following code into the "General Declarations"
section of Form1's Code Window:
Private Sub Command1_Click()
Dim rs As ADODB.Recordset
Dim rec As ADODB.Record
Set rs = New ADODB.Recordset
Set rec = New ADODB.Record
rs.Open "", "URL=http://localhost/", , , adCmdTableDirect
rec.Open rs
MsgBox rec(0).Value
rec.Close
Set rec = Nothing
rs.Close
Set rs = Nothing
End Sub
Private Sub Command2_Click()
Dim rs As ADODB.Recordset
Dim rec As ADODB.Record
Set rs = New ADODB.Recordset
Set rec = New ADODB.Record
rs.Open "Employees", "Provider=sqloledb;" & _
"Data Source=server;user id=sa;password=password;" & _
"initial catalog=northwind;", _
adOpenStatic, adLockReadOnly, adCmdTableDirect
'The error occurs on the following line:
rec.Open rs
rec.Close
Set rec = Nothing
rs.Close
Set rs = Nothing
End Sub
- Modify the Connection strings to point to your server and
database.
- Click F5 to start your Visual Basic program.
Click Command1. No error occurs when using the Internet Publishing
Provider.
Click Command2. Note the error when using the Microsoft Jet OLE DB
provider.