In. NET 2.0, the nullable model is provided. With it, we can assign null values to basic types such as int, so that we can process null values.
Sample Code
The data table has an updatetimestamp field, which can be a null value. Use the following settings in the object class:
Private datetime? _ Updatetimestamp;
/// <Summary>
/// File update date
/// </Summary>
Public nullable <datetime> updatetimestamp
{
Get {return this. _ updatetimestamp ;}
Set {This. _ updatetimestamp = value ;}
}
/// <Summary>
/// Load data from datareader
/// </Summary>
/// <Param name = "RDR"> </param>
Public void load (idatareader RDR)
{
If (RDR. Read ())
{
Isloaded = true;
This. fileid = (INT) RDR ["fileid"];
If (! RDR ["updatetimestamp"]. Equals (dbnull. Value ))
{
This. updatetimestamp = (datetime) RDR ["updatetimestamp"];
}
......
}
}
}
// Method for saving the file
Public abstract int createfile (......,, Datetime? Updatetimestamp, int downloadcount );
Obtain the value of the nullable Field
This. caldatepublished. selecteddate = This. file. updatetimestamp. value;
You cannot directly use this. caldatepublished. selecteddate = This. file. updatetimestamp;
Reference: http://blogs.msdn.com/ericgu/archive/2004/05/27/143221.aspx