|
|
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 |
|
|
Your Vote! |
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!
|
3/20/2002 2:45:52 PM:Igor Hi, you can use it this
way:
var=IIF(IsDBNull(YourValue)=False,
TrueCondition,FalseCondition)
:-)
|
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
|
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.
|
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.
|
5/23/2002 7:00:55 PM:Ian Ippolito (psc) No problem, Arp.
Ian
|
5/24/2002 10:07:02 AM:doit.rednight keep on , nice fellow
|
7/29/2002 4:06:10 PM:Jeff Rhine Thanks Ian! Exactly the information I
was looking for!
|
7/29/2002 8:01:58 PM:Ian Ippolito (psc) You're very welcome, Jeff. ;)
Ian
|
2/10/2003 3:32:13 AM:VBGOD Great!
|
4/14/2003 11:33:17 AM: If you just want to populate a string
this works great
too...rsCompany.Item("Name").ToString
|
7/20/2003 2:07:18 AM:Rick Winscot Imports System.Data.SqlTypes (FYI)
|
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!!
|
|
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. |
|