I am getting this exception from the following VB.NET code for only certain months:
System.InvalidCastException: Conversion from type \'DBNull\' to type \'Da
check for null with dRow.IsNull("CompleteDate") before you ask for the value.
Or if this is 'supposed to be' impossible, change your query to never return rows where it can be null.
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
<Global.System.Diagnostics.DebuggerStepThroughAttribute()> _
Friend Function GetDbStringValue(ByVal Dr As OleDbDataReader, ByVal nr As Integer) As String
#Else
<Global.System.Diagnostics.DebuggerStepThroughAttribute()> _
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