I'm converting an Access VBA app to VB.NET. It has dates defined as variants or objects to handle null values. I thought this would be a great chance to use the Nullable type. But I can't get it to work. Either it is inappropriate for what I am trying to use it for, or I am doing it wrong. Anyone know how to use it? Reader is a SqlDataReader.
ORCode:mdtDeniedDate = DirectCast(Reader("DeniedDate"), DateTime?)
The field returnsCode:mdtDeniedDate = CType(Reader("DeniedDate"), DateTime?)And I just get the error "Specified cast is not valid."{System.DBNull}
System.DBNull: {System.DBNull}
Declaration:
Even the statementCode:Private mdtDeniedDate As DateTime?Returns an error 'System.DBNull' cannot be converted to 'Date'.Code:mdtDeniedDate = Reader("DeniedDate")
I was hoping I didn't have to put a lot of If .. Null statements throughtout the code, but that is my only option unless someone has any other idea.




Reply With Quote