Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Column in recordset is null

Status
Not open for further replies.

pdbowling

Programmer
Mar 28, 2003
267
US
Hello, Everyone.

I am maintaining javascript code from another developer on Internet Explorer 8.

I have a recordset that returns only one field and that field is null.

A record exists but the value of the field is null.

I tried testing for null in the field value but I am missing something.

I thought the code below would catch it but it does not. The debug line writes 'myCount=Null'

How do I test for null if this is not the way?

Code:
if(curs("CountItems")) {
    myCount=curs("CountItems")
}
else{
    myCount=1
}

if(debug){
   Write("myCount=" + myCount+ "<br>")
}

Thanks, Everyone.
Patrick
 
This:

Code:
[b][COLOR=#0000FF]if[/color][/b][COLOR=#990000]([/color][b][COLOR=#000000]curs[/color][/b][COLOR=#990000]([/color][COLOR=#FF0000]"CountItems"[/color][COLOR=#990000]))[/color]

is testing for false. And False is not null. If you want to test for null you need to do it explicitly.

Code:
[b][COLOR=#0000FF]if[/color][/b][COLOR=#990000]([/color][b][COLOR=#000000]curs[/color][/b][COLOR=#990000]([/color][COLOR=#FF0000]"CountItems"[/color][COLOR=#990000])==[/color][b][COLOR=#0000FF]null[/color][/b][COLOR=#990000])[/color]


----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Web & Tech
 
The below code is outputting:
mc=null
2
This indicates that the test for null is not being recognized as null even though I just wrote it out and it Says null. (the reason I was testing the alternate code originally posted :-/). Am I missing some Method or Syntax?

Been reading this article about null in javascript as well

Still not sure I understand why this doesn't work.

Code:
        if (!curs.eof){
           Write("mc="+curs("CountItems")+"<br>")

           if(curs("CountItems")==null) {
              Write("1<br>")
              myCount=1
           }
           else{
              Write("2<br>")
              myCount=curs("CountItems")

              if(timesPerDay==0){
                 Write("3<br>")
                 myCount=1
              }
           }
        }
        else{
           Write("4<br>")
           myCount=1
        }
 
I have read dozens of articles about null being an object in javascript and the differences between null and underfined and evaluating nulls as booleans. I never quite ironed out what was happening in my code But ...

I changed the query to not bring back nulls .... ISNULL(myCount,0) AS MyCount.

Now I don't have to deal with it.

Thanks for the input.

Patrick
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top