469,900 Members | 1,649 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,900 developers. It's quick & easy.

Nothing vs dbnull.value

Hi

What is the difference between Nothing and dbnull.value?

Thanks

Regards
Mar 19 '08 #1
3 5027
John wrote:
Hi

What is the difference between Nothing and dbnull.value?
The important thing is that they are not the same.

Nothing generally refers to an object reference variable that is not a reference
to anything, that is, does not refer to any object.

DBNull.Value is not an object reference, but indicates that a value is Null. As
its name suggests, it usually means that in a database, that particular column,
in some particular row, is Null, even if the column is say an integer column. It
applies to values, not object references.
Mar 19 '08 #2
John,

Null tells that there is nothing as the reference to an object (in VB what
is not Ecla is using the keyword as it is "Nothing")
DBNull.Value is a value type (used as a database can return an empty value
and then returns that type)

Both are a kind of legacy from the past. By instance Intel based computers
initialize the declared memory with nulls char(00), other computers do that
with high values char(255). So "null" comes from the hardware and is
practicaly the use of a very low based program language as original C in
fact was. Let say as that we woud use AR for adding two fields (Add
Register) as it was in the beginning even before C.

Cor

"John" <in**@nospam.infovis.co.ukschreef in bericht
news:es**************@TK2MSFTNGP04.phx.gbl...
Hi

What is the difference between Nothing and dbnull.value?

Thanks

Regards
Mar 19 '08 #3
On Mar 18, 8:44 pm, "John" <i...@nospam.infovis.co.ukwrote:
Hi

What is the difference between Nothing and dbnull.value?

Thanks

Regards
As Steve has said, Nothing is basically a state of an object
reference. The reference is either pointing to something or nothing,
so when you are checking for 'is nothing' you are not looking at a
value of an object, but rather it's state. DbNull on the other hand,
does not refer to a state, but a value of an object. Nullable columns
have to be treated special by the database, and that fact must be
handled by .NET. When you receive a value from a database the
reference is pointing to a value, that value being DbNull.

The good news is, that most times you can forgo the search for DbNull.
Especially if you are using a datareader to pull the data, you can
simply do datareader("ColumnName").ToString() and .NET will convert a
DbNull into a blank string ""

Thanks,

Seth Rowe [MVP]
Mar 19 '08 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

11 posts views Thread by Patrick.O.Ige | last post: by
26 posts views Thread by Bob Day | last post: by
13 posts views Thread by Dune | last post: by
8 posts views Thread by MattB | last post: by
6 posts views Thread by tshad | last post: by
11 posts views Thread by Jethro | last post: by
1 post views Thread by Waqarahmed | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.