Groups | Blog | Home
all groups > dotnet general > june 2005 >

dotnet general : DateTime Null value in Typed DataSet gives Invalid Cast Exception - Please help !!!


Jon Skeet [C# MVP]
6/18/2005 12:00:00 AM
[quoted text, click to view]

There should be a method called IsDatePublishedNull autogenerated for
you.

--
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet
Fresh_Air_Rider NO[at]SPAM Hotmail.com
6/18/2005 7:48:09 AM
Hi Folks

I have a strongly typed dataset which works perfectly well until a NULL
value is returned for a DateTime field.

Whatever I try to do to test for a NULL value results in an Invalid
Cast Exception

I have tried Microsoft's suggestion of editing the XSD file as
follows:-

xmlns:codegen="urn:schemas-microsoft-com:xml-msprop"

nillable="true" msprop:nullValue="1980-01-01T00:00:00"

All of the following tests have resulted in an Invalid Cast Exception

_dsH.Headlines[0].DatePublished ==
System.DateTime.Parse("1980-01-01T00:00:00");

_dsH.Headlines[0].DatePublished == System.DBNull.Value;

_dsH.Headlines[0].DatePublished == SqlDateTime.Null.Value;

Could someone please give me a code snippet which tests a Typed DataSet
column of DateTime to see if it has a NULL value ?

Many thanks in advance

David Parry
Fresh_Air_Rider NO[at]SPAM Hotmail.com
6/18/2005 9:42:21 AM
Jon

Yes, you're right, there certainly is a method called
IsDatePublishedNull.

Many thanks for pointing that out.

Regards
David
AddThis Social Bookmark Button