Problem with null value for datetime field in a tableadapter

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?
 
R

rowe_newsgroups

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
 
K

k.knudsen

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'.
 
K

k.knudsen

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top