473,626 Members | 3,201 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Easy question, IIF and Convert with DBNulls

Max
Why doesn't this work:
cbAutoBill.Chec ked = IIf(IsDBNull(re ader("autobill" )), False,
Convert.ToBoole an(reader("auto bill")))
Gives error: Object cannot be cast from DBNull to other types.

But this does:
cbAutoBill.Chec ked = IIf(IsDBNull(re ader("autobill" )), False,
reader("autobil l"))

"autobill" is a bit

-Max
Nov 18 '05 #1
2 2010
I could be wrong but I think that everything in the IIF statements gets
evaluated even if it is not used so that when reader("autobil l") is null the
convert is evaluated and fails even though you don't want that value to be
used. I could be wrong but I think I've had it explained to me that way.
Have you tried this:

cbAutoBill.Chec ked = Convert.ToBoole an(IIf(IsDBNull (reader("autobi ll")),
False, reader("autobil l")))

Paul Ross
Hebco, Inc.

"Max" <no****@notvali d.com> wrote in message
news:OM******** ******@TK2MSFTN GP15.phx.gbl...
Why doesn't this work:
cbAutoBill.Chec ked = IIf(IsDBNull(re ader("autobill" )), False,
Convert.ToBoole an(reader("auto bill")))
Gives error: Object cannot be cast from DBNull to other types.

But this does:
cbAutoBill.Chec ked = IIf(IsDBNull(re ader("autobill" )), False,
reader("autobil l"))

"autobill" is a bit

-Max

Nov 18 '05 #2
Max
Oh you know you're right. I totally get it now. IIF is just a function like
any other. It accepts 3 variables, which are *obviously* going to be
evaluated and THEN sent to the function! Duh!

-Max

"Pross" <ta******@aol.c om> wrote in message
news:u2******** ******@tk2msftn gp13.phx.gbl...
I could be wrong but I think that everything in the IIF statements gets
evaluated even if it is not used so that when reader("autobil l") is null
the convert is evaluated and fails even though you don't want that value to
be used. I could be wrong but I think I've had it explained to me that way.
Have you tried this:

cbAutoBill.Chec ked = Convert.ToBoole an(IIf(IsDBNull (reader("autobi ll")),
False, reader("autobil l")))

Paul Ross
Hebco, Inc.

"Max" <no****@notvali d.com> wrote in message
news:OM******** ******@TK2MSFTN GP15.phx.gbl...
Why doesn't this work:
cbAutoBill.Chec ked = IIf(IsDBNull(re ader("autobill" )), False,
Convert.ToBoole an(reader("auto bill")))
Gives error: Object cannot be cast from DBNull to other types.

But this does:
cbAutoBill.Chec ked = IIf(IsDBNull(re ader("autobill" )), False,
reader("autobil l"))

"autobill" is a bit

-Max


Nov 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
1358
by: ben3003 | last post by:
I am only asking for my code to do a simple thing but for some reason i just can't get it to do what i want it to do... it been bugging me all day! The user inputs 2 dates on one page. in the form xx/xx/xxxx I then want the output page to display the amount of days that there are between these two dates, inclusive. For example: 01/01/2005 03/01/2005
0
1283
by: Alex | last post by:
Hi, an LPCTSTR is a long pointer to a const string. This is a windows typicall variable type like UINT, DWORD and so on. You can use it the same way like you would use standard variable types in c++, i.g. char, bool or int. To your second question. LPCWSTR is a long pointer to a const Unicode string. The W in variable types stands for Unicode. If you want to get more information on the
1
1427
by: Rachel | last post by:
My do while works the first time but the second time it breaks at the len = Convert.ToDouble(Console.ReadLine()); It says that I have an unhandled System format exception. Help! using System; using System.Text; namespace assignment1 {
13
1475
by: Ghislain Tanguay | last post by:
I have a compiled vb.net app and I want to give the user a choice to launch it from the start line command and pass it a parameter or not. How can I do that in my code? Is it possible? Ex. : MyApp.exe "Go"
3
1212
by: Jeff Calico | last post by:
Hi I have what I think is a easy question about how to pull cross reference data when I transform my XML file. I can't seem to find a good example of how to do this on the web, though. Here is the XML file I am supposed to process:
8
6610
by: John | last post by:
Is there any special code I have to write to log event to Security Event Log? The following code give me "Very Easy Question, How to write log to SECURTY Event Log? Please help" Error // Create an EventLog instance and assign its source. EventLog myLog = new EventLog(); myLog.Source = "Security"; // Write an informational entry to the event log. myLog.WriteEntry("Writing warning to event log.",
4
1908
by: robert.b.walden | last post by:
Hello, Easy question from a newbie. I have text boxes which collect users input and on the click of a button do some calculations and output to another text box. I need to easily convert the numbers inputted to int's so I can do the calculations. Also I need to figure out how to pop up an error box if the charactors entered in those boxes are anything but numbers. Thanks in advance for helping someone trying to learn this robust...
7
2443
by: SteveM | last post by:
I am sure this is an easy question, but being relatively new to ASP.NET programming, I can not quite grasp what I need to accomplish what I need to do. What I have is a word document that is rendered as a page (or actualy a part of a page) that is editiable. To do this I let the user download the document, edit it and then upload it back to the site. Then at Page_Open, I convert the .doc file to an html and render it back to the page......
21
7486
by: Aman JIANG | last post by:
hi I need to do this (convert double to string) fast, safe and portable. Is there any way to do this ? Except the ways following: 1. C++ I/O stream, stringstream (and boost::lexical_cast) 2. sprintf (and its brothers) 3. any nonstandard C/C++ functions
0
8196
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8705
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8364
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8504
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7193
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5574
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4092
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4197
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2625
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.