Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Handle DBNull that is a boolean

Posted on 2007-03-29
3
Medium Priority
?
508 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 2000 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

Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

Question has a verified solution.

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

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
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.
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

688 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