Prevent DBNull Exception on an Integer

JaedenRuiner

Well-known member
Joined
Aug 13, 2007
Messages
340
Programming Experience
10+
In the DataSet Designer, you can select a column, and adjust many properties.

One of the more important of which is: NullValue, which defaults to Throw Exception. You can additionally Select (Empty) or (Nothing), which works quite well for my string values.

But I have an Integer. basically, I added a column to a table, and all those entries are blank. I cannot "set" them to a default number, because that Violates Foreign Key constraints. Thus the Field must remain "Null" until such time as an entry in the Primary Key Table is available for the Foreign Key to be assigned to. But when I try to access the NULL field I keep getting an Exception.

I try setting to Empty/Nothing and I get a Property Error - "The value entered is not valid for the current data type." Well, duh, the data type is Integer, so why don't they have something else. It says up top, "AllowDBNull = True" so I want the null value, just return the NULL, instead of an exception. How can I work around this. I can just test "IsDBNull()" and i know where it is, but if it pops an exception EVERY TIME I won't even get that far.

Thanks
 
Have a look at Nullable(Of Integer).
 

Latest posts

Back
Top