I am having trouble passing an ADODB.Recordset from a VB6 application
to a VB.Net class library using COM Interop. I am running this on XP
SP2 with the .Net Framework 1.1 and MDAC 2.8 SP1.
I've compiled the VB.Net DLL and registered it so it can be used in the
VB6 app using "regasm /tlb:VBNETClass.tlb VBNETClass.dll". From the VB6
app, I added a reference to the VB.Net DLL. (Both classes also
reference the ADO 2.8 Library.) I then built the VB6 EXE and copied it
to the directory containing the VB.Net DLL.
When I run that EXE, all of the message boxes appear fine except for
the one on the last line of PrintRecordCount below. Instead, I get the
following error:
- - - -
Run-time error '-2147467262 (80004002)';
QueryInterface for interface ADODB._Recordset failed.
- - - -
(The debugger shows it to be a System.InvalidCastException.)
Any ideas?
VB6 APP
Private Sub Command1_Click()
Dim ccw As New VBNETClass.Class1
Dim rs As New ADODB.Recordset
Set rs = CreateObject("ADODB.Recordset")
rs.CursorType = adOpenStatic
rs.CursorLocation = adUseClient
rs.Fields.Append "FieldName1", adVarChar, 10
rs.Fields.Append "FieldName2", adInteger
rs.Open
rs.AddNew
rs("FieldName1") = "David"
rs("FieldName2") = 17
rs.Update
rs.Sort = "FieldName2"
rs.MoveFirst
MsgBox ("In VB6 App, about to call VB.Net class...")
MsgBox ("In VB6 Class, rs.RecordCount = " & rs.RecordCount)
ccw.PrintRecordCount (rs)
End Sub
VB.NET CLASS LIBRARY
Public Class Class1
Public Function PrintRecordCount(ByVal rs As ADODB.Recordset)
MsgBox("In VB.Net Class, about to display RecordCount... ")
[[[[START OF ERROR LINE]]]]
MsgBox("In VB.Net Class, rs.RecordCount = " & rs.RecordCount)
[[[[END OF ERROR LINE]]]]
End Function
End Class
(I also tried changing the type of the input parameter to
ADODB.RecordsetClass but the same error resulted.)