Solved

Handle DBNull that is a boolean

Posted on 2007-03-29
3
486 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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

706 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now