COM Interoperability - Object type to Dataset

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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
 
Hi, Prasad,

The recommendation is the following:

The .OLE DB .NET Data Provider includes overloads to the
OleDbDataAdapter.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-us/dnsql2k/html/sql_adonetprimer.asp

Greetings
Martin
Prasad said:
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.
 
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.GetMovieCodes(); // 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.Object
OleDbDataAdapter oda = new OleDbDataAdapter()
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.Common.DbDataAdapter.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
 
Hi, prasad,

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

See also this article:
http://msdn.microsoft.com/library/en-us/cpguide/html/cpconfillingdatasetwithadorecordset.asp

Greetings
Martin
prasad said:
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.GetMovieCodes(); // 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.Object"
OleDbDataAdapter oda = new OleDbDataAdapter();
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.Common.DbDataAdapter.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.
 
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.GetStateCodes()

now when I use this object gsc

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

If i di
OleDbDataAdapter oda = new OleDbDataAdapter()
DataSet ds = new DataSet()
ADODB._Recordset adors = (Recordset)ep.GetStateCodes()
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
 
Well,.....

The method GetRows returns two dimensional array:

http://msdn.microsoft.com/library/en-us/ado270/htm/mdmthgetrows.asp

Hope this helps
Martin
Prasad said:
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.GetStateCodes();

now when I use this object gsc

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

If i did
OleDbDataAdapter oda = new OleDbDataAdapter();
DataSet ds = new DataSet();
ADODB._Recordset adors = (Recordset)ep.GetStateCodes();
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"
 
Back
Top