Mam problemy z Nullable DateTime w VB.NET (VS.NET).VB.NET - Nullyble DateTime and Ternary Operator
Metoda 1
If String.IsNullOrEmpty(LastCalibrationDateTextBox.Text) Then
gauge.LastCalibrationDate = Nothing
Else
gauge.LastCalibrationDate = DateTime.Parse(LastCalibrationDateTextBox.Text)
End If
Metoda 2
gauge.LastCalibrationDate = If(String.IsNullOrEmpty(LastCalibrationDateTextBox.Text), Nothing, DateTime.Parse(LastCalibrationDateTextBox.Text))
Kiedy podano pusty ciąg Metoda 1 przypisuje Null (Nic) Wartość gauge.LastCalibrationDate ale Metoda 2 przypisuje go DateTime.MinValue.
W innych miejscach w moim kodu mam:
LastCalibrationDate = If(IsDBNull(dr("LastCalibrationDate")), Nothing, dr("LastCalibrationDate"))
to poprawnie przypisuje Null (nic) z potrójnego Operatora do pustych DateTime.
Czego mi brakuje? Dzięki!
+1 Dobra robota, dodając obejście, które przyniesie pożądany rezultat. –