473,327 Members | 2,090 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

Checking for a null value in a datareader

RSH
I have a situation where I am looping through a datareader's rows. An
exception is being generated when I attempt to check the value of a Boolean
field where it has a null value:\

If VarType(dtrList["ServiceCenter"]) != VariantType.Null And
dtrList["ServiceCenter"] = True Then

chkAssignedGroups.Items[0].Selected = True

End If

What is the correct way to do this?

Thanks,

Ron


Jul 13 '06 #1
2 4989

RSH wrote:
I have a situation where I am looping through a datareader's rows. An
exception is being generated when I attempt to check the value of a Boolean
field where it has a null value:\

If VarType(dtrList["ServiceCenter"]) != VariantType.Null And
dtrList["ServiceCenter"] = True Then

chkAssignedGroups.Items[0].Selected = True

End If
Wow, and I thought *I* was bad at remembering what language I was using
:) So which is it?

--
Larry Lard
Replies to group please
When starting a new topic, please mention which version of VB/C# you
are using

Jul 13 '06 #2

if (!(dataReader.IsDBNull(0)))
{
currentOrder.CustomerID = dataReader.GetString( 0);
}
Its C#, but the property of IsDBNull (int) should be the same.



"RSH" <wa*************@yahoo.comwrote in message
news:Ov**************@TK2MSFTNGP05.phx.gbl...
I have a situation where I am looping through a datareader's rows. An
exception is being generated when I attempt to check the value of a
Boolean
field where it has a null value:\

If VarType(dtrList["ServiceCenter"]) != VariantType.Null And
dtrList["ServiceCenter"] = True Then

chkAssignedGroups.Items[0].Selected = True

End If

What is the correct way to do this?

Thanks,

Ron


Jul 13 '06 #3

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

Similar topics

99
by: Mikhail Teterin | last post by:
Hello! Consider the following simple accessor function: typedef struct { int i; char name; } MY_TYPE; const char *
7
by: Dan | last post by:
I'm fairly new to C# and I am having some problems understanding int variables and null values. I have created a class that populates the values of it's fields from a DataReader in it's...
5
by: Rene | last post by:
I have my object model thing going with some classes that contain properties that are saved into a database. Some of these properties are *numeric* properties that can be left Null in the database...
3
by: tshad | last post by:
I am trying to set up a class to handle my database accesses. I can't seem to figure out how to get the return value from my dataReader from these routines (most of which I got elsewhere). They...
4
by: Lakota61 | last post by:
I have an application where a database entity that progresses through a cycle. As it completes a step along the cycle, a todays date is assign to one of the date columns in the table row. However...
4
by: Learner | last post by:
Hello, This my a method to call a stored proce and uses a DataReader to read the data in the below method I am trying to assign a null value to my datareader variable Dim datareader As...
4
by: Patient Guy | last post by:
Does anyone have any coding rules they follow when doing argument checking? When arguments fail during check, do you return from the call with an ambiguous return value, or do you throw...
5
by: axapta | last post by:
Hi Group, How can I overcome the issue of null values in a datareader. I keep getting the dbnull error when I try to assign a null value to a text box. TIA
10
by: =?Utf-8?B?R3JlZw==?= | last post by:
I have the following three files. 1. Users.aspx is a webpage that uses the <asp:ObjectDataSourcecontrol to populate a simple <asp:ListBoxcontrol. 2. The UserDetails.cs file creates a Namespace...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.