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.
Try this: aRow.IsSomeFieldNull
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With