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 / Windows Forms / WinForm General / August 2005

Tip: Looking for answers? Try searching our database.

Checking for Null Value Unsuccessful

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
kache - 08 Aug 2005 16:32 GMT
I retrieve data from sql dbo and place within a dataset datatable using a
simple select statement. One of the fields is nullable and the data returned
may be null. When I use IsDBNull(dr.("fieldname")), the check fails because
the actual contents are the characters "<NULL>". I can check the string value
for "<NULL>" and find it, but I cannot use IsDBNull, dr.IsNull("fieldname"),
or = System.DBNull.Value. Why is the null value being treated as a string and
filled in with the "<NULL>"?
Patrice - 08 Aug 2005 18:26 GMT
Have you checked the value stored in the DB ? Is it really NULL or already
the "<NULL>" string ?

Signature

Patrice

> I retrieve data from sql dbo and place within a dataset datatable using a
> simple select statement. One of the fields is nullable and the data returned
[quoted text clipped - 3 lines]
> or = System.DBNull.Value. Why is the null value being treated as a string and
> filled in with the "<NULL>"?
kache - 08 Aug 2005 18:46 GMT
I double-checked, but no, it is a true value in the dbo. When I write the
dataset containing the datatable to an xml document, the null value in the
field element is &ltNull&gt. If I check the string content value for equality
against the string value "<NULL>" then it works. This does not make sense to
me at all. I should be able to check for null.

> Have you checked the value stored in the DB ? Is it really NULL or already
> the "<NULL>" string ?
[quoted text clipped - 11 lines]
> and
> > filled in with the "<NULL>"?
Patrice - 09 Aug 2005 08:11 GMT
First once you get the DataTable back, can you check for NULL as expected
before saving to an XML document ?

For now I'm trying to understand at which step you have a problem and
especially if you have this problem once the DataTable is persisted to an
XML Document (and then restored ?)

It would allow to know if the problme is in getting back the data or
saving/restoring to an XML document.

Signature

Patrice

> I double-checked, but no, it is a true value in the dbo. When I write the
> dataset containing the datatable to an xml document, the null value in the
[quoted text clipped - 17 lines]
> > and
> > > filled in with the "<NULL>"?
TC - 09 Aug 2005 11:40 GMT
Why does that not make sense?

"<NULL>" and NULL are two different values. If it truly is "<NULL>" in
the database, then it is not NULL, and testing it for NULL will be
False - as it should be! No mysteries there.

The only real question is, why did the database designers or
programmers choose to use the string value "<NULL>", instead of leaving
the field NULL? You would have to ask them that.

HTH,
TC
kache - 09 Aug 2005 13:40 GMT
I loop through the datatable using for each dr in datatable.rows ... . When I
check for the null value in a specific field location (not the string value),
the null value is never flagged. The value in the database is a true null
value (not a <NULL> string value). I used dataset.writexml to look at the
contents of the datatable and that is when I observed &ltNULL&gt. I also
observed in the watch window the value <NULL>. Then when I check for the
string equivalent instead of the is null value check, the value is flagged.
The whole situation does not make a bit of sense to me either. Since the code
is somewhat deep, my belief is that somewhere that field must be getting
translated into a string value equal to <NULL> (as described by TC).
TC - 09 Aug 2005 17:55 GMT
I still don't understand why you are confused..

Forget how the value gets exported to XML or whatever. Focus on what
the value is in the database.

The value in the database is either NULL, or it is NOT NULL.

If it is NULL, then it can not possibly be "<NULL>".

Conversely, if it is "<NULL>" - or any other string value - then
clearly, it is not NULL.

You test for NULL using your database's "is NULL" operator, whatever
that is, and you test for "<NULL>", if you wish to do that, using a
normal = test.

You do understand that:     IF this = that      is /always False/, if
either 'this' or 'that' is NULL?

HTH,
TC
Patrice - 10 Aug 2005 10:23 GMT
What if you try your own bare bone code against the DB ?

If it works correctly then you'll have to dig into the application data
access code where there is likely such a translation.

If it still doesn't work it could be done server side. Make sure you checked
in the DB the exact same object that is used in your code, for example the
server table could have true NULL values but if for example you are using a
strored proc or a view it could be "translated" here.

The last thing I see would be an unausal column (for example I believe
Oracale has huge numbers).

Good luck.
Signature

Patrice

> I loop through the datatable using for each dr in datatable.rows ... . When I
> check for the null value in a specific field location (not the string value),
[quoted text clipped - 6 lines]
> is somewhat deep, my belief is that somewhere that field must be getting
> translated into a string value equal to <NULL> (as described by TC).
TC - 10 Aug 2005 10:53 GMT
I suspect he's not sure how to check for NULL.

He said (slightly reworded): "The value in the database is a true null
value, not a <NULL> string value. [But] when I check for the null value
..., not the string value, the null value is never flagged."

My bet: he is saying:    IF <field> = NULL ...

TC
TC - 10 Aug 2005 11:00 GMT
Or - he is checking for IS NULL properly, but the value is an empty
string - so it just "looks" NULL.

TC

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.