473,385 Members | 1,341 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,385 software developers and data experts.

Comparing to DBNull

Which is better:

SomeValue is DBNull
or
SomeValue == DBNull.Value

Thanks,
Michael Culley

Nov 16 '05 #1
4 11045
I think this is better:
Convert.IsDBNull(SomeValue);

and the 'is' keyword can not be used in this case
"Michael Culley" wrote:
Which is better:

SomeValue is DBNull
or
SomeValue == DBNull.Value

Thanks,
Michael Culley

Nov 16 '05 #2
googou <go****@discussions.microsoft.com> wrote:
I think this is better:
Convert.IsDBNull(SomeValue);

and the 'is' keyword can not be used in this case


Yes it can. The only value of DBNull is DBNull.Value - any reference
which "is" a DBNull is DBNull.Value, so

if (x is DBNull) is exactly equivalent to if (x==DBNull.Value). The
only difference using Convert.IsDBNull is if x is an instance of a type
which implements IConvertible with a GetTypeCode method returning
TypeCode.DBNull.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #3
Hi!

From my PoV:
"SomeValue == DBNull.Value"
should be faster than
"SomeValue is DBNull"

In the first case the only reference is compared.
The second case is Type compatibility comparison that
i believe need more time.

Of course these cases work in 100%!

Cheers!

Marcin
Which is better:

SomeValue is DBNull
or
SomeValue == DBNull.Value

Thanks,
Michael Culley

Nov 16 '05 #4
Hi,

"Marcin Grzębski" <mg*******@taxussi.no.com.spam.pl> wrote in message
news:cj**********@nemesis.news.tpi.pl...
Hi!

From my PoV:
"SomeValue == DBNull.Value"
should be faster than
"SomeValue is DBNull"

I agree with you, it's faster and IMO more legible.
cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation


Nov 16 '05 #5

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

Similar topics

5
by: Mark | last post by:
Assume that "some_app_setting" does not exist in my web.config file. Then, the first line of code below assigns the value null to strApplication. Why doesn't my IF statement return true, and...
7
by: | last post by:
Source Error: Line 173: sData(rownumber - 1, lcnt) = WhatCol.Value Line 174: End IF Line 175: If (sData(rownumber, lcnt) = sData(rownumber - 1, lcnt)) AND...
4
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...
11
by: Jeff | last post by:
Hi - I'm experiencing a strange problem when comparing 2 guids. In my trial, they're not equal. When I step through the (VB.NET) code, they are evaluated as equal, and when I enter the...
8
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...
6
by: tshad | last post by:
I have a value coming from my Object (or it could also be from a SqlDbReader) where I need to test for DBNull and 0. I tried to do it in one call: if (not (newPosition.ReportsTo is...
2
by: Kevin | last post by:
I'm trying to convert a VB6 app to VB2005. I'm trying to search for changes made to a record and record them in a log file. This is my code in VB6: Dim X As Long Dim oField As ADODB.Field Dim...
19
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
5
by: Leon Mayne | last post by:
We currently have lots of checks in our businesslayer object's Load() functions that look like: If drCourse("txtTTMCnotes").Equals(DBNull.Value) Then Me._txtTTMCnotes = "" Else...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.