Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / VB.NET / March 2008

Tip: Looking for answers? Try searching our database.

Nothing vs dbnull.value

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
John - 19 Mar 2008 01:44 GMT
Hi

What is the difference between Nothing and dbnull.value?

Thanks

Regards
Steve Gerrard - 19 Mar 2008 02:27 GMT
> 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.
Cor Ligthert[MVP] - 19 Mar 2008 06:06 GMT
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

> Hi
>
[quoted text clipped - 3 lines]
>
> Regards
rowe_newsgroups - 19 Mar 2008 12:27 GMT
> Hi
>
[quoted text clipped - 3 lines]
>
> 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]

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.