VB.NET - Nullable DateTime und Ternärer Operator

Ich habe Probleme mit einem Nullable DateTime in VB.NET (VS 2010).

Methode 1

If String.IsNullOrEmpty(LastCalibrationDateTextBox.Text) Then
    gauge.LastCalibrationDate = Nothing
Else
    gauge.LastCalibrationDate = DateTime.Parse(LastCalibrationDateTextBox.Text)
End If

Methode 2

gauge.LastCalibrationDate = If(String.IsNullOrEmpty(LastCalibrationDateTextBox.Text), Nothing, DateTime.Parse(LastCalibrationDateTextBox.Text))

Gegeben, wenn eine leere Zeichenfolge Methode 1 weist eine Null (Nichts) Wert zu Messen.LastCalibrationDate aber Methode 2 weist die DateTime.MinValue.

In anderen Orten in meinem code habe ich:

LastCalibrationDate = If(IsDBNull(dr("LastCalibrationDate")), Nothing, dr("LastCalibrationDate"))

Dies richtig weist Null (Nichts) aus einer Ternären Operator, um eine Nullable DateTime.

Was bin ich? Danke!

InformationsquelleAutor anonymous | 2010-11-15
Schreibe einen Kommentar