Solved

Handle DBNull that is a boolean

Posted on 2007-03-29
3
500 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

Question has a verified solution.

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

The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

752 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