PDF (US Ltr)
- 6.2Mb
PDF (A4)
- 6.2Mb
HTML Download (TGZ)
- 2.8Mb
HTML Download (Zip)
- 2.9Mb
The .NET DateTime
data type cannot handle
NULL
values. As such, when assigning values
from a query to a DateTime
variable, you must
first check whether the value is in fact
NULL
.
When using a MySqlDataReader
, use the
.IsDBNull
method to check whether a value is
NULL
before making the assignment:
Visual Basic Example
If Not myReader.IsDBNull(myReader.GetOrdinal("mytime")) Then
myTime = myReader.GetDateTime(myReader.GetOrdinal("mytime"))
Else
myTime = DateTime.MinValue
End If
C# Example
if (! myReader.IsDBNull(myReader.GetOrdinal("mytime")))
myTime = myReader.GetDateTime(myReader.GetOrdinal("mytime"));
else
myTime = DateTime.MinValue;
NULL
values will work in a data set and can
be bound to form controls without special handling.