jvoros1
asked on
C# error "specified cast is not valid"
Hello Expert, I am getting an error when i try to do this
aDataSet = (DataSet) dataGrid1.DataSource;
Do you know why i would get specified cast is not valid i got it from
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemwindowsformsdatagridclassdatasourcetopic.asp so i am not sure why it would not work. Can you help me?
Thanks
aDataSet = (DataSet) dataGrid1.DataSource;
Do you know why i would get specified cast is not valid i got it from
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemwindowsformsdatagridclassdatasourcetopic.asp so i am not sure why it would not work. Can you help me?
Thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks for you help I see my problem now my dataGrid.DataSource = aDataTable not a aDataSet
so i changed it to aDataTable = (DataTable) dataGrid1.DataSource;
And it works great :)
so i changed it to aDataTable = (DataTable) dataGrid1.DataSource;
And it works great :)
DataSet* myDataSet;
myDataSet = dynamic_cast<DataSet*> (dataGrid1->DataSource);
You want to cast a pointer to an object, not cast the actual object.