473,387 Members | 1,464 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Passing a Recordset from VB6 to VB.Net (QueryInterface failed.)

I am getting an error when trying to use an ADODB.Recordset that was passed
from a VB6 application to a VB.Net class library using COM Interop. I am
running this on WinXP SP2 using the .Net Framework 1.1 and MDAC 2.8 SP1.

This is what I've done:
- I 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.
- I added references to the ADO 2.8 Library from both the VB6 app and the
VB.Net library. (I also tried ADO 2.6 and 2.7 later but they had the same
results.)
- I built the VB6 EXE and copied it to the directory containing the VB.Net
DLL.

When I run the VB6 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...")
' this line works
MsgBox ("In VB6 Class, rs.RecordCount = " & rs.RecordCount)

ccw.PrintRecordCount (rs)

End Sub

VB.NET CLASS LIBRARY (VBNETClass)

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

MsgBox("In VB.Net Class, about to display RecordCount... ")
' this line produces the error
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 and ADODB._Recordset but the same error resulted.)

Nov 22 '05 #1
0 1480

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Jason | last post by:
I'm writing a small console app in .NET that needs to reference a 3rd party dll. I wrote the app by adding a reference to the 3rd party dll in my project and my code builds and executes...
0
by: matt | last post by:
Hi There we have a new asp.net site that is getting a lot of hits. I have set this up on its own server with its own database server. We have a search system built into the site which is timing...
0
by: Dot Netizen | last post by:
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...
0
by: adam | last post by:
I am getting an error when trying to use an ADODB.Recordset that was passed from a VB6 application to a VB.Net class library using COM Interop. I am running this on WinXP SP2 using the .Net...
27
by: Oscar | last post by:
I am looking for a way to pass an ADO recordset that has been retrieved in an ASP page to another HTML-page. Is there someone who can provide me with a small sample or a link to see how this is...
0
by: Deeps | last post by:
Hi I have created an interface called IGlobal with some properties exposed with a fixed Guid. Created a class inherting this interface. This is my com+ server. I have a client instantiating this...
0
by: Mullin Yu | last post by:
hi, i got an error QueryInterface for interface DocMgr._clsDocMgr failed where DocMgr is a COM object written by VB6. I just compiled DocMgr with a changed revision but SAME classid (binary...
4
by: Ram | last post by:
I am running a test web site on my own Win2k professional computer. I have a VB6 COM component (running on COM+) on a seperate application runnint as "Server". When running an ASP.NET page calling...
1
by: Michael Connerton | last post by:
The company I work for still uses Excel97. In a weaker moment I added the pia for Excel2003 in attempt to get more programatic functionality out of some Excel interfaces I have been writing. The...
1
by: adiel_g | last post by:
Hello, I have created a activeX dll in vb6 that contains some functions I am using in .NET. I created the dll in vb6 with: Instancing = 5-Multiuse MTSTransactionMode = 2-RequiresTransaction...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.