I'm having problems with a Nullable DateTime in VB.NET (VS 2010).
Method 1
If String.IsNullOrEmpty(LastCalibrationDateTextBox.Text) Then
gauge.LastCalibrationDate = Nothing
Else
gauge.LastCalibrationDate = DateTime.Parse(LastCalibrationDateTextBox.Text)
End If
Method 2
gauge.LastCalibrationDate = If(String.IsNullOrEmpty(LastCalibrationDateTextBox.Text), Nothing, DateTime.Parse(LastCalibrationDateTextBox.Text))
When given an empty string Method 1 assigns a Null (Nothing) value to gauge.LastCalibrationDate but Method 2 assigns it the DateTime.MinValue.
In other places in my code I have:
LastCalibrationDate = If(IsDBNull(dr("LastCalibrationDate")), Nothing, dr("LastCalibrationDate"))
This correctly assigns Null (Nothing) from a Ternary Operator to a Nullable DateTime.
What am I missing? Thanks!