Conversion from type 'DBNull' to type 'Date' is not valid

前端 未结 2 1642
滥情空心
滥情空心 2020-12-21 01:37

I am getting this exception from the following VB.NET code for only certain months:

System.InvalidCastException: Conversion from type \'DBNull\' to type \'Da         


        
2条回答
  •  Happy的楠姐
    2020-12-21 01:54

    I use a sub (different for each datatype) to get data from a Datareader, using the index instead of the name though:

    #If Access Then
     _
    Friend Function GetDbStringValue(ByVal Dr As OleDbDataReader, ByVal nr As Integer) As String
    #Else
     _
    Friend Function GetDbStringValue(ByVal Dr As MySqlDataReader, ByVal nr As Integer) As String
    #End If
        If IsDBNull(Dr.Item(nr)) Then
            Return ""
        Else
            Return Dr.GetString(nr).TrimEnd
        End If
    End Function
    

提交回复
热议问题