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

F

Fresh_Air_Rider

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
 
J

Jon Skeet [C# MVP]

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

There should be a method called IsDatePublishedNull autogenerated for
you.
 
F

Fresh_Air_Rider

Jon

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

Many thanks for pointing that out.

Regards
David
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top