DateTime Data Types and SQL Server NULL

  • Thread starter Thread starter E. R. Retzloff
  • Start date Start date
E

E. R. Retzloff

Any suggestions on how to track a NULL value received from SQL Server in a
DateTime field? I have come up with two and I'm not convinced either of them
are good solutions.

1. Assign a predetermined value (DateTime.Date.MaxValue... or something like
that) in place of NULL and check for that when necessary. Seems a little
Y2K-ish to me.

2. Use a companion Boolean variable (e.g. bool dateIsNull) to track the
status. Not such a bad idea but seems tedious to keep them in sync.

On a side note, I have some data architecture/ADO.NET/SQL Server/C# concerns
I would like to discuss with someone or a group of someones ;). Any
suggestions? (I know, that may be a little too specific, but there doesn't
seem to be a newsgroup that would apply without possibly offending someone
and I really don't want to cross-post.)

TIA - Eric
 
Box your values on the way in and out of the database in an object...
either the "object" type or one of your own creation... and handle the
change over manually. I use my own boxing types and provide a
".ToValueOrNull()" method that... in the case of dates... provides a
dbnull if the date it contains is a pre-set bogus date (jan 1, 1901),
etc.
 
Back
Top