Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Checking for DBNull throws a StrongTypingException

I am using a dataset to pull data from a DB. One of the fields in a row is NULL. I know this. However, the following vb.net code throws a StrongTypingException (in the autogenerated get_SomeField() method in the dataset designer):

If Not IsDBNull(aRow.SomeField) Then
'do something
End If

According to documentation and this question it should be fine.

edit: If aRow.SomeField is DBNull.Value Then also returns the same error. Argh.

like image 657
calico-cat Avatar asked Jan 14 '11 09:01

calico-cat


2 Answers

Try this: aRow.IsSomeFieldNull

like image 146
royas Avatar answered Nov 15 '22 16:11

royas


Just some additional information: The exception comes because you are using a strongly typed DataSet. StrongTypingException documentation says it:

The exception that is thrown by a strongly typed DataSet when the user accesses a DBNull value.

The usage of strongly typed DataSets is slightly different from that of the untyped ones. With strongly typed DataSets you get automatically some extended/additional methods for your fields that you can call. In your case you would very likely have to call:

If Not aRow.IsSomeFieldNull Then
   'do something
End If
like image 35
MicSim Avatar answered Nov 15 '22 16:11

MicSim