Ah, the standard "magic value" approach. Unforunately, this is a core
problem that Microsoft is getting closer to solving with Nullable types in
..NET 2.0.
However, in .NET 1.x, you have three main solutions:
1. The Ostrich Approch - Basically make all your DateTime fields
non-nullable and put your head in the sand with regards to the existence of
"unknown" date time values.
2. The "Magic Value" Approach that Ignacio mentioned. In this scenario you
pick a "magic value" for the given data type to represent an "unknown"
value. This approach has numerous caveats. The first is that if your system
is ever required to integrate with someone else's system who used a
different magic value, you will have problems. In addition, if that "magic
value" ever becomes a real value, you will have a bunch of work to do to
make a new "magic value." Lastly, it will be inordinately difficult on new
developers and report writers that come in when they have to have the "holy
magic value" list for every field (since some fields may have different
magic values).
3. The "I live in a world based on reality and am using .NET 1.x"
You have two subchoices here. One is to the SqlTypes. They allow for nulls
and are generally handled most places in ASP.NET. The problem with SqlTypes
is that they are not serializable. So if that is at all a possible need, you
have to move to the second choice. The second choice is to build your own
nullable type that mimics the primitives but allows for nulls (e.g. DBInt32,
DBInt16, DBDateTime etc.) This is more of a pain to be sure, but does allow
you to handle any sort of null as well as to store actual nulls in the
database.
I really wish Microsoft would build more database driven enterprise systems
that actually have database nulls and use business objects in the middle
tier. Were they to do that, they would realize that nulls need to propogate
all the way to the presentation layer as Fabiano has discovered.
Thomas
"Ignacio Machin ( .NET/ C# MVP )" <ignacio.mach in AT dot.state.fl.us > wrote
in message news:uI******** ******@tk2msftn gp13.phx.gbl...
Hi,
Please clarify more your problem.
Just remember something, DateTime does not support null, you would have
to
select an extreme value like ,DateTime.MinVa lue to represent null
Cheers,
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"Fabiano" <a@a.com.br> wrote in message
news:eT******** *****@tk2msftng p13.phx.gbl... Please,
i have an webform, that work with a object that receives a DateTime
value.
I don't want to save date into it. How can i verify if it's value is null
or
not?
Tks
Fabiano