473,659 Members | 2,965 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

COM Interoperabilit y - Object type to Dataset

Hi

I have a legacy DLL, that has functions which accept and return type "Variant"
I want to use that DLL in .NET. I am able to use functions well that return variants but that return common data types like string, int etc

There is one function that has a return type variant, but actually returns a recordset
the return type of variant in .NET is treated as Syste.Object

I am unable to type cast the Object(actually a recordset) to dataset

Any ideas on this?

Thank
Prasad
Nov 18 '05 #1
5 2601
Hi, Prasad,

The recommendation is the following:

The .OLE DB .NET Data Provider includes overloads to the
OleDbDataAdapte r.Fill method which take as input an ADO Recordset or Record
object returned by existing COM components, and populate a DataSet with the
data contained in the ADO object.
http://msdn.microsoft.com/library/en...onetprimer.asp

Greetings
Martin
"Prasad" <an*******@disc ussions.microso ft.com> wrote in message
news:67******** *************** ***********@mic rosoft.com...
Hi,

I have a legacy DLL, that has functions which accept and return type "Variant". I want to use that DLL in .NET. I am able to use functions well that return variants but that return common data types like string, int etc.
There is one function that has a return type variant, but actually returns a recordset. the return type of variant in .NET is treated as Syste.Object.

I am unable to type cast the Object(actually a recordset) to dataset.

Any ideas on this?

Thanks
Prasad

Nov 18 '05 #2
Thanks for ther eply
I think from what you have said, the return needs to be either of type 'ADO Recordset' or 'Record object". What I can capture is only pure "object
Attached is a brief snipped of the code

A.DataClass ep = new A.DataClass()
object gsc = ep.GetMovieCode s(); // the return here is of type System.Object. The actuall dll has a return type of Variant.
// The actual value taht is returned in the DLL is of type Recordset. I can only capture the return as type "object"

Response.Write( "gsc= "+ gsc.GetType()); // prints out "System.Obj ect
OleDbDataAdapte r oda = new OleDbDataAdapte r()
DataSet ds = new DataSet()
ADODB.Recordset adoRS = new ADODB.Recordset ()
oda.Fill(ds, gsc)

I get the following error: The best overloaded metho
The best overloaded method match for 'System.Data.Co mmon.DbDataAdap ter.Fill(System .Data.DataSet, string)' has some invalid argument
Argument '2': cannot convert from 'object' to 'string

The function does not seem to recognize that as a valid object, and tries to use another overloaded fucntion that has string as a param

Any further ideas.

Thanks agai
Prasad
Nov 18 '05 #3
Hi, prasad,

You should use the overload
int Fill(DataSet dataSet, object ADODBRecordSet, string srcTable)
http://msdn.microsoft.com/library/en...filltopic2.asp

See also this article:
http://msdn.microsoft.com/library/en...orecordset.asp

Greetings
Martin
"prasad" <an*******@disc ussions.microso ft.com> wrote in message
news:39******** *************** ***********@mic rosoft.com...
Thanks for ther eply.
I think from what you have said, the return needs to be either of type 'ADO Recordset' or 'Record object". What I can capture is only pure "object" Attached is a brief snipped of the code:

A.DataClass ep = new A.DataClass();
object gsc = ep.GetMovieCode s(); // the return here is of type System.Object. The actuall dll has a return type of Variant. // The actual value taht is returned in the DLL is of type Recordset. I can only capture the return as type "object".
Response.Write( "gsc= "+ gsc.GetType()); // prints out "System.Obj ect"
OleDbDataAdapte r oda = new OleDbDataAdapte r();
DataSet ds = new DataSet();
ADODB.Recordset adoRS = new ADODB.Recordset ();
oda.Fill(ds, gsc);

I get the following error: The best overloaded method
The best overloaded method match for 'System.Data.Co mmon.DbDataAdap ter.Fill(System .Data.DataSet, string)' has
some invalid arguments Argument '2': cannot convert from 'object' to 'string'

The function does not seem to recognize that as a valid object, and tries to use another overloaded fucntion that has string as a param.
Any further ideas.

Thanks again
Prasad

Nov 18 '05 #4
Thanks very much for ur reply. But I am still having trouble. The solutions that you are providing are for the ADODB recordsets that are created in .NET client

I am using a COM DLL that has a following funciton. (main lines of the code are as below

Public Function GetStateCodes() As Varian
On Error GoTo adoErro
If Not adoRset.EOF The
GetStateCodes = adoRset.GetRows (
End I
Exit Functio
adoError
GetStateCodes = "Error
End Functio

The return type is a variant(though recordset is being cast

When using this function in .NET, I can only capture the return value in "object
object gsc = ep.GetStateCode s()

now when I use this object gsc

OleDbDataAdapte r oda = new OleDbDataAdapte r()
DataSet ds = new DataSet()
oda.Fill(ds, gsc, "state")
I get "Object is not an ADODB.Recordset or an ADODB.Record.

If i di
OleDbDataAdapte r oda = new OleDbDataAdapte r()
DataSet ds = new DataSet()
ADODB._Recordse t adors = (Recordset)ep.G etStateCodes()
oda.Fill(ds, adors, "state")
I get "Specified Cast not valid", If I remove the cast into adors, i get:"Cannot implicitly convert type object to ADODB.Recordset

I cant think of anything else. Would appreciate any other thoughts.
Sincere thanks for ur replies

- Prasa
Nov 18 '05 #5
Well,.....

The method GetRows returns two dimensional array:

http://msdn.microsoft.com/library/en...mthgetrows.asp

Hope this helps
Martin
"Prasad" <an*******@disc ussions.microso ft.com> wrote in message
news:2B******** *************** ***********@mic rosoft.com...
Thanks very much for ur reply. But I am still having trouble. The solutions that you are providing are for the ADODB recordsets that are
created in .NET client.
I am using a COM DLL that has a following funciton. (main lines of the code are as below)
Public Function GetStateCodes() As Variant
On Error GoTo adoError
If Not adoRset.EOF Then
GetStateCodes = adoRset.GetRows ()
End If
Exit Function
adoError:
GetStateCodes = "Error"
End Function

The return type is a variant(though recordset is being cast)

When using this function in .NET, I can only capture the return value in "object" object gsc = ep.GetStateCode s();

now when I use this object gsc

OleDbDataAdapte r oda = new OleDbDataAdapte r();
DataSet ds = new DataSet();
oda.Fill(ds, gsc, "state");
I get "Object is not an ADODB.Recordset or an ADODB.Record."

If i did
OleDbDataAdapte r oda = new OleDbDataAdapte r();
DataSet ds = new DataSet();
ADODB._Recordse t adors = (Recordset)ep.G etStateCodes();
oda.Fill(ds, adors, "state");
I get "Specified Cast not valid", If I remove the cast into adors, i get:"Cannot implicitly convert type object to ADODB.Recordset "
I cant think of anything else. Would appreciate any other thoughts.
Sincere thanks for ur replies.

- Prasad

Nov 18 '05 #6

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

Similar topics

7
3340
by: Mark | last post by:
I built the example application outlined in this artical: http://msdn.microsoft.com/library/default.asp? url=/library/en-us/dnservice/html/service02112003.asp There were a number of questions along the same lines posted to the page's discussion forum but no one replied with a solution. The problem I am experiencing is with the 3rd example.
3
4010
by: Sai Kit Tong | last post by:
Hi, I am developing a new application running on Windows platform that needs to interface with existing legacy code - written in basic C / C++. I am trying to evaluate Java vs C# implementations. Originally, I have the impression that C# should be a clear winner. I started with Java and using the guideline from the book "Java Native Interface". Though complex, the book provide details of the practical implementation and potential...
3
2371
by: Sai Kit Tong | last post by:
I posted for help on legacy code interface 2 days ago. Probably I didn't make it clear in my original mail. I got a couple of answers but none of them address my issues directly (See attached response). My first reply directed me to source code migration but I didn't have the source code. The second reply mentioned about .NET interoperability (PInvoke I think) but I MENTIONED THAT I COULDN'T FIND ANY DOCUMENTATION FROM MSDN LIBRARY BASED ON...
2
1514
by: GeRmIc | last post by:
hi friends, This is really urgent, Pls. Can C access C# classes? I am doing an interop with a C# library and a C library. The code for the C# library is like this
0
975
by: paccala | last post by:
Ciao! Reposting here from aspnet.webservices as I didn't have answers... I would like to return the content of a datatable in an interoperable way. I cannot use typed datasets and return an XmlDataDocument, or return a list of custom classes because my application is generic and I know the number and type of attributes only run-time. What is the best strategy to implement an interoperable webservice in this case? Creating an...
1
5545
by: J. Askey | last post by:
I am implementing a web service and thought it may be a good idea to return a more complex class (which I have called 'ServiceResponse') in order to wrap the original return value along with two other properties... bool error; string lastError; My whole class looks like this... using System;
13
2154
by: andrea | last post by:
Sorry for the stupid question, I know, but sometimes is necessary starts from the basic. I don't know how to pass the result of a method generated from a DAL class to a BL class returning the results as it is. I mean, for instance, something like this. namespace DAL {
10
3860
by: Arpan | last post by:
Consider the following code that adds a table to a DataSet dynamically: <script runat="server"> Sub Page_Load(ByVal obj As Object, ByVal ea As EventArgs) 'Create an empty DataSet Dim dSet As New DataSet 'Create a new table & add columns Dim dTable As New DataTable("Users") dTable.Columns.Add("ID", Type.GetType("System.Int32"))
35
3202
by: Chris | last post by:
Hi, I tried to create a class which must change the propety 'visible' of a <linktag in the masterpage into 'false' when the user is logged. But i get the error: "Object reference not set to an instance of an object" for the line 'If mpg.FindControl("lkred").Visible = True Then'. I couldn't find sofar the solution. Any help would be appreciated ... Thanks
0
8428
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8335
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8851
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
6179
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5649
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4175
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4335
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1976
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1737
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.