Date.TryParse and AS/400 dates

  • Thread starter Thread starter Mike Loux
  • Start date Start date
M

Mike Loux

Has anyone else run into this problem? I am pulling date values from
an AS/400 DDS file via OleDb using an SQL statement. Sometimes (and
there does not seem to be any rhyme or reason to this), when I do a
Date.TryParse on a date field that is empty, I get the current date
instead of Date.MinValue. Time is 12 AM, like it should be. Kind of
throws off your validation when you're expecting 01/01/0001 and you
get 10/27/2008 instead. :-)

I have tried just doing away with the TryParse and dealing with the
field as-is (after all, it is a date field, should always get a date
value, right?), but that sometimes leads to Object Reference Not Set
errors and the like. Very strange. For now I am just checking the
value in the field, and if it's blank, I use Date.MinValue by
default.

Oh yes, this is .Net Framework 2.0. That probably would help. Thanks!
 
Mike said:
Has anyone else run into this problem? I am pulling date values from
an AS/400 DDS file via OleDb using an SQL statement. Sometimes (and
there does not seem to be any rhyme or reason to this), when I do a
Date.TryParse on a date field that is empty, I get the current date
instead of Date.MinValue. Time is 12 AM, like it should be. Kind of
throws off your validation when you're expecting 01/01/0001 and you
get 10/27/2008 instead. :-)
There's rarely such a thing as "no rhyme or reason" when it comes to
computers, and DateTime.TryParse() (there is no "Date.TryParse") definitely
doesn't contain a random number generator. What do the strings you pass to
..TryParse() actually contain?

It may be as simple as running into fields that are empty vs. running into
fields that are NULL. Conversions with NULL can be wonky, especially if no
type is associated with the value.

Since you show no code, it's hard to tell what might be going wrong.
 
Back
Top