체크하면 날짜에 열 datatable is null
문제
Dim dr As SqlDataReader = cmd.ExecuteReader(CommandBehavior.CloseConnection)
Dim dt As DataTable = New DataTable()
dt.Load(dr)
For Each row As DataRow In dt.Rows
Dim dob_str As String = ""
'code to check if row.Field(Of Date)("DOB") is dbnull
'if not dbnull then dob_str = row.Field(Of Date)("DOB")
Next
어떻게 확인하는 경우 Date
유형 열 각 행에 대해 DataTable
은 비어 있습니까?
나
If Not row.Field(Of Date)("DOB") = Nothing Then
dob_str = row.Field(Of Date)("DOB")
End If
고
Dim nullCheck As Boolean = IsDBNull(row.Field(Of Date)("DOB"))
If nullCheck = False Then
dob_str = row.Field(Of Date)("DOB")
End If
하지만 그들은 모두 결과 Cannot cast DBNull.Value to type 'System.DateTime'. Please use a nullable type.
중 런타임입니다.
제휴하지 않습니다 StackOverflow