By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,680 Members | 1,486 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,680 IT Pros & Developers. It's quick & easy.

Passing an ADODB.Recordset from VB6 to VB.Net

P: n/a
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?

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("FieldName1") = "David"
rs("FieldName2") = 17

rs.Sort = "FieldName2"

MsgBox ("In VB6 App, about to call VB.Net class...")
MsgBox ("In VB6 Class, rs.RecordCount = " & rs.RecordCount)

ccw.PrintRecordCount (rs)

End Sub

Public Class Class1
Public Function PrintRecordCount(ByVal rs As ADODB.Recordset)

MsgBox("In VB.Net Class, about to display RecordCount... ")
MsgBox("In VB.Net Class, rs.RecordCount = " & rs.RecordCount)

End Function
End Class

(I also tried changing the type of the input parameter to
ADODB.RecordsetClass but the same error resulted.)

Jul 21 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.