Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / Interop / January 2005

Tip: Looking for answers? Try searching our database.

Passing an ADODB.Recordset from VB6 to VB.Net (QueryInterface fail

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
adam - 12 Jan 2005 16:19 GMT
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.)
adam - 13 Jan 2005 17:55 GMT
Peter, thanks for the reply. I tried your code and the VB6 app successfully
executes this line:

- - - -
' this line works
   MsgBox ("In VB6 Class, rs.RecordCount = " & rs.RecordCount)
- - - -

But then I get this error:

- - - -
Run-time error '430':
Class does not support Automation or does not support expected interface
- - - -

Any ideas?

> 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
[quoted text clipped - 66 lines]
> (I also tried changing the type of the input parameter to
> ADODB.RecordsetClass and ADODB._Recordset but the same error resulted.)

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.