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.
。