Quick Search for:  in language:    
ADO,NULL,youre,programmer,frustrated,knowing,
   Code/Articles » |  Newest/Best » |  Community » |  Jobs » |  Other » |  Goto » | 
CategoriesSearch Newest CodeCoding ContestCode of the DayAsk A ProJobsUpload
.Net Stats

 Code: 140,189. lines
 Jobs: 376. postings

 How to support the site

 
Sponsored by:

 
You are in:
 

Does your code think in ink?
Login





Latest Code Ticker for .Net.
Click here to see a screenshot of this code!Ray Picking for 3d Objects
By Jay1_z on 11/23

(Screen Shot)

Embed Images into Xml Files
By Chris Richards on 11/23


Encryption and Alternate Data Stream
By Philip Pierce on 11/23


Click here to see a screenshot of this code!AddressBook
By Ekong George Ekong on 11/23

(Screen Shot)

Click here to see a screenshot of this code!Command Line Redirection
By kaze on 11/23

(Screen Shot)

Fader
By Ahmad Hammad on 11/23


Click here to see a screenshot of this code!Get content of a web page (simple)
By Tin Trung Dang on 11/22

(Screen Shot)

Retrieve the long path name for a short path name.
By Özgür Aytekin on 11/22


Easy Randomizer
By Christian Müller on 11/22


Click here to put this ticker on your site!


Add this ticker to your desktop!


Daily Code Email
To join the 'Code of the Day' Mailing List click here!

Affiliate Sites



 
 
   

Quick tip on how to handle NULL in ADO.net

Print
Email
 

Submitted on: 3/15/2002 3:29:39 PM
By: Ian Ippolito (RAC)  
Level: Beginner
User Rating: By 14 Users
Compatibility:VB.NET, ASP.NET

Users have accessed this article 11702 times.
 

(About the author)
 
     If you're an old ADO programmer, you may be frustrated by not knowing exactly how to check for NULL. Here's a 1 second tip on how to do it in ADO.NET.

 
 
Terms of Agreement:   
By using this article, you agree to the following terms...   
1) You may use this article in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.   
2) You MAY NOT redistribute this article (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
3) You may link to this article from another website, but ONLY if it is not wrapped in a frame. 
4) You will abide by any additional copyright restrictions which the author may have placed in the article or article's description.

If you try the old fashioned way of checking for null:

    If IsNull(rsCompany("Name")) Then

Visual Studio will tell you that IsNull is not supported and to use DBNull instead.  At first I thought this was really nice.  However, when I tried to do:

    If rscompany("Name") = DBNull Then

I got an error about assignments not allowed to a type!  What was I to do?

The Visual Studio help was its usual cryptic self ("The DBNull class is for handling NULL values"...accurate by not alot of help).  After some fumbling around, I stumbled on the answer, and thought I'd share it to hopefully save someone 5 minutes of having to research it:

     If rsCompany("Name") is DBNull.Value then

Hope this saves you some time!

 


Other 10 submission(s) by this author

 

 
Report Bad Submission
Use this form to notify us if this entry should be deleted (i.e contains no code, is a virus, etc.).
Reason:
 
Your Vote!

What do you think of this article(in the Beginner category)?
(The article with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor See Voting Log
 
Other User Comments
3/17/2002 7:28:12 PM:computrz
you rule Ian! I have the ticker on my desktop and saw the headline, and you saved me more than five minutes, if only I seen it sooner. Thanx!
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
3/20/2002 2:45:52 PM:Igor
Hi, you can use it this way: var=IIF(IsDBNull(YourValue)=False, TrueCondition,FalseCondition) :-)
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
3/20/2002 5:18:56 PM:Ian Ippolito (psc)
Good point Igor...I only found out about IsDBNull myself a few days ago (the .NET help is just not that much "help") and meant to post it up...that's a great addendum. Ian
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
5/11/2002 1:39:45 AM:Stoney
Also, I found that when working with Nulls, and you are just trying to, lets say populate a string variable with a value from the database, you can... strCompanyName = rsCompany("Name") & "" Gives you a zero length string if rsCompany("Name") evaluates to Null.
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
5/23/2002 1:10:09 PM:Arp
You saved me lots of time and hassle. None of the books I'm using even have a reference to 'null' or 'dbnull'. The little things always seem to cause the biggest problems. Thanks again.
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
5/23/2002 7:00:55 PM:Ian Ippolito (psc)
No problem, Arp. Ian
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
5/24/2002 10:07:02 AM:doit.rednight
keep on , nice fellow
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
7/29/2002 4:06:10 PM:Jeff Rhine
Thanks Ian! Exactly the information I was looking for!
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
7/29/2002 8:01:58 PM:Ian Ippolito (psc)
You're very welcome, Jeff. ;) Ian
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
2/10/2003 3:32:13 AM:VBGOD
Great!
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
4/14/2003 11:33:17 AM:
If you just want to populate a string this works great too...rsCompany.Item("Name").ToString
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
7/20/2003 2:07:18 AM:Rick Winscot
Imports System.Data.SqlTypes (FYI)
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
11/5/2003 3:26:20 PM:
Ian, you are the man. Thanks pal. My 4 hours of research has finally found a couple of minutes answer. Great job!!
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
Add Your Feedback!
Note:Not only will your feedback be posted, but an email will be sent to the code's author in your name.

NOTICE: The author of this article has been kind enough to share it with you.  If you have a criticism, please state it politely or it will be deleted.

For feedback not related to this particular article, please click here.
 
Name:
Comment:

 

Categories | Articles and Tutorials | Advanced Search | Recommended Reading | Upload | Newest Code | Code of the Month | Code of the Day | All Time Hall of Fame | Coding Contest | Search for a job | Post a Job | Ask a Pro Discussion Forum | Live Chat | Feedback | Customize | .Net Home | Site Home | Other Sites | About the Site | Feedback | Link to the Site | Awards | Advertising | Privacy

Copyright© 1997 by Exhedra Solutions, Inc. All Rights Reserved.  By using this site you agree to its Terms and Conditions.  Planet Source Code (tm) and the phrase "Dream It. Code It" (tm) are trademarks of Exhedra Solutions, Inc.