Click to See Complete Forum and Search --> : System.DBNull.Value


softwarenovice
02-07-2005, 06:37 AM
Hi

I am having some trouble using System.DBNull.Value. How do i assign this to other variables - say an integer variable or a boolean variable. If i try to cast it, i get a runtime error.

pclement
02-07-2005, 09:03 AM
The Visual Basic numeric based data types cannot contain System.DBNull values. This class is typically used for database operations. What is it that you are trying to do?

softwarenovice
02-07-2005, 10:52 PM
i am trying to store db null values in the database. I am passing the values from the front end to the middle component. So while passing the values , i have to store them somewhere and this is where i encounter problems

Phil Weber
02-08-2005, 01:18 PM
The simplest solution is to pass the values in Object variables, which may be null. The downside, of course, is that you lost strong-typing: it's possible to pass a string value to a function which expects an integer.

A cleaner, but more complex solution is to create custom nullable types, e.g.:

Structure NullableInteger
Value As Integer
HasValue As Boolean
End Structure

Pass instances of these structures between your tiers. If HasValue = False, then the variable is null; otherwise, it's equal to the Value property.