Converting DataSet to object type

G

George Durzi

I want to convert a dataset to type object so I can pass it to a generalized
function which accepts an object and adds it to the cache.

If I pass it in like:
Convert.ChangeType(MyDataSet, typeof(object))
or
(object)Convert.ChangeType(MyDataSet, typeof(object))

I get an InvalidCastException, with a message of Object must implement
IConvertible.

System.Data.DataSet doesn't implement IConvertible. Is there another way to
cast the DataSet as an object?
 
M

Michael Per

You don't need to convert or cast anything. If you have a function that
accepts Object then it will accept DataSet as well since DataSet inherits
from Object (as all other objects do).

If you insist however on explicit casting, this will do:
VB:
dim o as Object = MyDataSet
C#:
Object o = (Object) MyDataSet
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,818
Latest member
Brigette36

Latest Threads

Top