Solved

Handle DBNull that is a boolean

Posted on 2007-03-29
3
495 Views
Last Modified: 2013-11-07
I've created the following custom function:

Public Function DBNullToBoolean(ByVal Value) As Boolean
      If Value Is DBNull.Value Then
          Return False
      Else
          Return Value
      End If
End Function

...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?
0
Comment
Question by:rogue_1
  • 2
3 Comments
 
LVL 35

Accepted Solution

by:
mrichmon earned 500 total points
ID: 18819422
The best way (if possible) is to use nullable boolean type.  However, I say "if possible" because this is only available in .NET 2.0.  But since you are asking this in the .NET 2 forum, it should be possible for you.

Then using it you have the option to test .HasValue to see if it is null or if it is actually a boolean.  If so then you use .Value to get the bool value out.
0
 

Author Comment

by:rogue_1
ID: 18823781
OK, I will give that a try this weekend and let you know how it turns out.  Thanks
0
 

Author Comment

by:rogue_1
ID: 18838537
Works great.  Thanks for the help
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

820 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question