Problem with null value for datetime field in a tableadapter

  • Thread starter Thread starter k.knudsen
  • Start date Start date
K

k.knudsen

I am going through a dataset with dates and I would like to compare
date fields. Example on next line.

If CoreEmployeeBirthDate <> Me.DSeePersonal.eePersonal(0).BirthDate
Then

I hit a date that is null and I get the following exception:

Throw New System.Data.StrongTypingException("The value for column
'BirthDate' in table 'eePersonal' is DBNull.", e)

Is there anyway around this exception check?
 
I am going through a dataset with dates and I would like to compare
date fields. Example on next line.

If CoreEmployeeBirthDate <> Me.DSeePersonal.eePersonal(0).BirthDate
Then

I hit a date that is null and I get the following exception:

Throw New System.Data.StrongTypingException("The value for column
'BirthDate' in table 'eePersonal' is DBNull.", e)

Is there anyway around this exception check?

You could always check the value for dbnull before comparing it.

Something like:

If Me.DSeePersonal.eePersonal(0).BirthDate <> DbNull AndAlso
CoreEmployeeBirthDate <> Me.DSeePersonal.eePersonal(0).BirthDate Then
....
End If

Thanks,

Seth Rowe
 
You could always check the value for dbnull before comparing it.

Something like:

If Me.DSeePersonal.eePersonal(0).BirthDate <> DbNull AndAlso
CoreEmployeeBirthDate <> Me.DSeePersonal.eePersonal(0).BirthDate Then
...
End If

Thanks,

Seth Rowe

Thanks Seth, but I get the following error when trying to check for
dbnull:

Overload resolution failed because no accessible '=' can be called
with these arguments:
'Public Shared Operator =(d1 As Date, d2 As Date) As Boolean': Value
of type 'System.DBNull' cannot be converted to 'Date'.
 
Thanks Seth, but I get the following error when trying to check for
dbnull:

Overload resolution failed because no accessible '=' can be called
with these arguments:
'Public Shared Operator =(d1 As Date, d2 As Date) As Boolean': Value
of type 'System.DBNull' cannot be converted to 'Date'.- Hide quoted text -

- Show quoted text -

I found the answer. I need the following line:

If Me.DSeePersonal.eePersonal(0).IsBirthDateNull Then
 
Back
Top