Converting DataSet to object type

  • Thread starter Thread starter George Durzi
  • Start date Start date
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?
 
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
 
Back
Top