I am using the MS Data Access Application Blocks helper classes to execute
SQL statements against a SQL Server 2000 database and return datasets. I
have created a strongly typed dataset from an XSD file, which obviously
inherits the System.Data.Dataset class.
I am then trying to cast the System.Data.Dataset return type from the
SqlHelper.ExecuteDataset method to my strongly typed dataset but get a
"specified cast is not valid" error.
Can anyone please help with this problem?
This is a limitation of object oriented design. You can't cast a base class
to a derived class unless the base class was created by casting the derived
e.g. assume class A is a base class and class B inherits from it. Then:
Dim X As A = New A(): Dim Y As B = A ' this will fail - not allowed
Dim X As A = New B(): Dim Y As B = A ' this will work since was
originally type B
To work around the problem, you will have to change the DAAB to use your
typed DataSet class instead of the generic DataSet class.
Microsoft Developer Support
This posting is provided "AS IS", with no warranties, and confers no rights.
Are you secure? For information about the Strategic Technology Protection
Program and to order your FREE Security Tool Kit, please visit