Handle DBNull that is a boolean
Posted on 2007-03-29
I've created the following custom function:
Public Function DBNullToBoolean(ByVal Value) As Boolean
If Value Is DBNull.Value Then
...then using only one line of code if the database has a NULL value for "SubmittedIndicator" in the statement below, I can save a value into blnSubmitted variable which is declared as a Boolean, without getting a conversion type error
blnSubmitted = DBNullToBoolean(TABLENAME.Rows(0).Item("SubmittedIndicator"))
However, when I go to save the data back to the database, the variable contains 'False' and might possibly still should be a NULL value since the user may not have specified its value.
TABLENAME.Rows(0).Item("SubmittedIndicator") = blnSubmitted
I cannot think of a way to ensure when saving the data back to the database that I may need to be saving NULL value, if that is what was passed in.
What is the best way to handle this?