Safe Save DateTime to SQL Database.

When I tried to save DateTime data to SQL database, I’ve got 
SqlDateTime overflow. Must be between 1/1/1753 12:00:00 AM and 12/31/9999 11:59:59 PM.
I’ve had to create a function
object SafeSqlDateTime(DateTime dtValue)
{
object theValue = dtValue;
if (dtValue <(DateTime) SqlDateTime.MinValue) // January 1, 1753.
{
   theValue =
null;

}
return theValue;

For opposite SqlDateTime to DateTime Conversion see
http://msdn.microsoft.com/en-us/library/aa326475(VS.71).aspx
 
Advertisements