DateTime Data Types and SQL Server NULL

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • E. R. Retzloff

    #1

    DateTime Data Types and SQL Server NULL

    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


  • Chris Hornberger

    #2
    Re: DateTime Data Types and SQL Server NULL

    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.

    "E. R. Retzloff" <eretzloff_at_h otmail_dot_com> wrote in message news:<#hDTeozVD HA.1680@tk2msft ngp13.phx.gbl>. ..[color=blue]
    > 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[/color]

    Comment

    Working...