Solved

C# error "specified cast is not valid"

Posted on 2004-03-30
3
609 Views
Last Modified: 2012-05-04
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
0
Comment
Question by:jvoros1
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 12

Accepted Solution

by:
dfiala13 earned 500 total points
ID: 10714924
Make sure the DataSource on the grid is not null.  If you are trying to make this call after a postback, the DataSource property will be null and you will not be able to cast.

0
 
LVL 69

Expert Comment

by:Callandor
ID: 10714942
The example shows
DataSet* myDataSet;
myDataSet = dynamic_cast<DataSet*> (dataGrid1->DataSource);

You want to cast a pointer to an object, not cast the actual object.
0
 

Author Comment

by:jvoros1
ID: 10714968
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 :)
0

Featured Post

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

695 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question