这是我的代码 -
Dim provider As CultureInfo = CultureInfo.InvariantCulture
Dim a1 As DateTime = Nothing
insexp = DateTime.ParseExact(date1.SelectedValue, "MMMM yyyy", provider)
If a1.Month = Today.Month AndAlso a1.Year = Today.Year Then
a1 = Today.Date
End If
仅当date1.selectedvalue不为null时才会起作用,但如果为null则会崩溃。 如果条件不运行,我该怎么办? 感谢
答案 0 :(得分:5)
If date1.SelectedValue IsNot Nothing Then
...
End If
答案 1 :(得分:1)
Dim provider As CultureInfo = CultureInfo.InvariantCulture
Dim a1 As DateTime = Nothing
If not String.IsNullOrEmpty(date1.SelectedValue) Then
insexp = DateTime.ParseExact(date1.SelectedValue, "MMMM yyyy", provider)
End If
If a1.Month = Today.Month AndAlso a1.Year = Today.Year Then
a1 = Today.Date
End If