Solved

Handle DBNull that is a boolean

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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

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 article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

623 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