Posts Tagged ‘Null Values’

How to assign Null Values to Date Type Variable in .Net

Actually, you can’t assign a null value to a Date Type variable but you can check if the variable has been set or not by comparing its current value versus default value (#12:00:00 AM#) of date/datetime, you can get the default value by using

  1. Date.MinValue or DateTime.MinValue

To do this, let say you have a variable called LastUpdate with a data type of Datetime

  1. Dim LastUpdate  as DateTime
  2. dim dr as Datarow
  3.  
  4. If DateTime.MinValue = LastUpdate   Then
  5.         'Its Null value
  6.         'if you want to save the value to the database then use the DBNull.Value
  7.         dr("LastUpdate") = DBNull.Value
  8. Else
  9.         dr("LastUpdate") =LastUpdate  
  10. End If

, ,

No Comments



SetPageWidth