Strongly Typed Dataset Invalid Cast Error When value is NULL

Strongly Typed Dataset Invalid Cast Error When value is NULL

Post by Jaso » Thu, 30 Jan 2003 15:17:41



hello all, i have been pulling my hair out over this one for an entire day,
so i hope someone might know what i'm talking about.  i actually found
someone else with the same problem and it saves me some typing to just give
you the link to that whole discussion:
http://www.dotnet247.com/247reference/msgs/16/82772.aspx

anyway, the problem is that, when using a strongly typed DataSet, DataTable
and DataRow, when a NULL value is encountered, an invalid cast exception is
thrown.  the exception is thrown by the strongly typed DataSet class, which
is of course automatically generated by .NET based on an XSD file that i
create.  so, manually editing that class is counter-productive.

it is easy to catch this exception, or even to avoid it by retreiving the
value in different ways.  the main problem is that it can't be bound to a
DataGrid as-is because this exception will occur. so, all of the
work-arounds are great when you are dealing with a single row and a single
value.  but if you're trying to bind it to a user control, it doesn't work.

does anyone have experience with this particular problem?  i would like to
hear how you are dealing with it.

thanks,
j

 
 
 

Strongly Typed Dataset Invalid Cast Error When value is NULL

Post by Peter Boh » Thu, 30 Jan 2003 17:59:44


Hi Jason,

i overloaded the indexer of the DataRow class to avoid this problem....

Peter


Quote:> hello all, i have been pulling my hair out over this one for an entire
day,
> so i hope someone might know what i'm talking about.  i actually found
> someone else with the same problem and it saves me some typing to just
give
> you the link to that whole discussion:
> http://www.dotnet247.com/247reference/msgs/16/82772.aspx

> anyway, the problem is that, when using a strongly typed DataSet,
DataTable
> and DataRow, when a NULL value is encountered, an invalid cast exception
is
> thrown.  the exception is thrown by the strongly typed DataSet class,
which
> is of course automatically generated by .NET based on an XSD file that i
> create.  so, manually editing that class is counter-productive.

> it is easy to catch this exception, or even to avoid it by retreiving the
> value in different ways.  the main problem is that it can't be bound to a
> DataGrid as-is because this exception will occur. so, all of the
> work-arounds are great when you are dealing with a single row and a single
> value.  but if you're trying to bind it to a user control, it doesn't
work.

> does anyone have experience with this particular problem?  i would like to
> hear how you are dealing with it.

> thanks,
> j


 
 
 

Strongly Typed Dataset Invalid Cast Error When value is NULL

Post by David Brown » Thu, 30 Jan 2003 23:54:13


see
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpgu...
l/cpconusingannotationswithtypeddataset.asp

for how to change the behaviour of the generated dataset class
when an attempt is made to access the strongly-typed column
which is null on that row.

Your choices are:
 -throw and exception (the default)
 -return Nothing (null in C#)
 -return some fixed value like '' for null string columns, or 0 for numerics

David

your choice


> hello all, i have been pulling my hair out over this one for an entire
day,
> so i hope someone might know what i'm talking about.  i actually found
> someone else with the same problem and it saves me some typing to just
give
> you the link to that whole discussion:
> http://www.dotnet247.com/247reference/msgs/16/82772.aspx

> anyway, the problem is that, when using a strongly typed DataSet,
DataTable
> and DataRow, when a NULL value is encountered, an invalid cast exception
is
> thrown.  the exception is thrown by the strongly typed DataSet class,
which
> is of course automatically generated by .NET based on an XSD file that i
> create.  so, manually editing that class is counter-productive.

> it is easy to catch this exception, or even to avoid it by retreiving the
> value in different ways.  the main problem is that it can't be bound to a
> DataGrid as-is because this exception will occur. so, all of the
> work-arounds are great when you are dealing with a single row and a single
> value.  but if you're trying to bind it to a user control, it doesn't
work.

> does anyone have experience with this particular problem?  i would like to
> hear how you are dealing with it.

> thanks,
> j

 
 
 

Strongly Typed Dataset Invalid Cast Error When value is NULL

Post by Jaso » Fri, 31 Jan 2003 06:43:32


it's a christmas miracle!  thank you, that is exactly what i was looking
(and hoping) for.

-jason



Quote:> see

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpgu...
Quote:> l/cpconusingannotationswithtypeddataset.asp

> for how to change the behaviour of the generated dataset class
> when an attempt is made to access the strongly-typed column
> which is null on that row.

 
 
 

1. Strongly typed dataset - can't find strongly typed row type

Hello,

I'm using a strongly typed dataset.  When iterating thru the rows
collection, i would prefer to use the strongly typed row data type,
instead of using system.data.datarow.  It doesn't seem to be available
from intellisense, but it compiles correctly and it is a public class.

Is this a vs.net bug?

Thx,
Doug

2. HD controller for Z80 ???

3. how do you pass NULL DateTime values to a strongly typed DataSet?

4. backup of long filemane

5. Problem Casting from Dataset to Strongly Typed Dataset

6. dns cash

7. Problem setting field to null in a strongly typed dataset.

8. Strongly typed datasets Nulls and Databinding!

9. Help req:Null fields in strongly typed datasets

10. Typed Dataset invalid cast exception problem

11. strongly typed DataSet original values

12. Accessing deleted values in strongly typed datasets