473,836 Members | 2,300 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Test for DBNull

How do I test for DBNull? The following does not work.
System.Data.Dat aRow aRow;
if (aRow["ServerName "] != null)

{

aServer = (string)aRow["ServerName "];

}
Nov 15 '05 #1
4 76876
MFRASER,

You can check against the static value property of DBNull, like so:

if (aRow["ServerName "] != DBNull.Value)

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"MFRASER" <mf*****@henwoo denergy.com> wrote in message
news:un******** ******@TK2MSFTN GP12.phx.gbl...
How do I test for DBNull? The following does not work.
System.Data.Dat aRow aRow;
if (aRow["ServerName "] != null)

{

aServer = (string)aRow["ServerName "];

}

Nov 15 '05 #2
MFRASER wrote:
How do I test for DBNull? The following does not work.


Try using .IsDBNull(field );

--
Mike Swaim sw***@hal-pc.org at home
mp*****@mdander son.org or ms****@odin.mda cc.tmc.edu at work
Disclaimer: Yeah, like I speak for MD Anderson.
Quote: "Boingie"^4 Y,W & D
Nov 15 '05 #3
There's a neat discussion by Dino Esposito that touches on some interesting
issuses associated with reading SQL NULL types in C#.

http://msdn.microsoft.com/vcsharp/de...datareader.asp

Hope this helps,
Michael McD.

"Mike Swaim" <mp*****@mdande rson.org> wrote in message
news:ub******** ******@TK2MSFTN GP09.phx.gbl...
MFRASER wrote:
How do I test for DBNull? The following does not work.


Try using .IsDBNull(field );

--
Mike Swaim sw***@hal-pc.org at home
mp*****@mdander son.org or ms****@odin.mda cc.tmc.edu at work
Disclaimer: Yeah, like I speak for MD Anderson.
Quote: "Boingie"^4 Y,W & D

Nov 15 '05 #4
Hi,

There is also aRow.IsNull method.

--
Miha Markic - RightHand .NET consulting & development
miha at rthand com
www.rthand.com

"MFRASER" <mf*****@henwoo denergy.com> wrote in message
news:un******** ******@TK2MSFTN GP12.phx.gbl...
How do I test for DBNull? The following does not work.
System.Data.Dat aRow aRow;
if (aRow["ServerName "] != null)

{

aServer = (string)aRow["ServerName "];

}

Nov 15 '05 #5

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

Similar topics

5
7476
by: DraguVaso | last post by:
Hi, Something I don't understand about a Typed DataSet: When a value in the DataSet is DBNull, it throws this error: "Cannot get value because it is DBNull". But aren't Typed DataSets invented to make life easier, to be able to get to tge Tables and Values with less code, in less time? But with this thing you need to add a Try-Catch around every statement when using the value, add for each value a default value in your DataSet (and...
1
6621
by: Vern | last post by:
I'm using the Microsoft Enterprise Data Access block to call the stored procedure. One of the values the stored procedure returns is the stop date. When the stop date is null, the program crashes. I would like to be able to test for a null date, and then store the mindate value in the class property. I've tried the following, but it still crashes. if (dbCommandWrapper.GetParameterValue("@StopDt") == null) {
4
1734
by: Tina | last post by:
I have instantiated an insertRow for a dataset. I now want to make the GLCode DBNull. I have tried: insertRow.GLCode = Convert.dbnull insertRow.GLCode = Convert.dbnull(insertRow.GLCode) and several other things. How is it done?
8
17525
by: MattB | last post by:
Hello. I have a vb.net (asp.net) application that uses ado.net datasets. At one point, I need to check a text field in a DataTable to see if there's any text in it before performing text operations on that record. I thought I could just test using something like this: If Not IsNothing(e.Item.DataItem("guest_name")) Then .... End If But it seems a value of DBNull passes this test and evaluates as not
4
13255
by: moondaddy | last post by:
How can I test to see if an object is System.DBNull? I have an event and need to get the value from a parameter like this: Private Sub ValueChanged(ByVal sender As Object, ByVal e As System.EventArgs) Try Dim ID As Int32 'Next line is suto code. it doesnt compile If sender.Value Is System.DBNull Then
10
2427
by: Bob | last post by:
I'm sure there's a good reason, I just haven't been able to think of it - why didn't MS allow "DBNull" values to simply be a null (Nothing)? Bob
6
27317
by: cj | last post by:
in the command window I get: ? result {System.DBNull} : {System.DBNull} I need to check for this in code. I then tested in the command window if result = system.DBNull 'DBNull' is a type and cannot be used as an expression.
3
6698
by: AAJ | last post by:
Hi all A quick question on Datasets..... I populate a dataset from a SQL SERVER 2000 database via a data adapter. I then use the dataset to populate member variables of my class. I know the datatype of a column in the database, so I use convert. to convert the results in to the same datatype within my class i.e.
19
19352
by: Dave | last post by:
If Iwant to check if dataset1.SelectQuery1.column1 == System.DBNull.Value. How do I do this? What I wrote above will give an error. -- L. A. Jones
0
9810
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10821
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...
0
10527
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10241
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...
1
7773
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6973
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
5642
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
5812
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4443
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.