Wrox Home  
Search P2P Archive for: Go

  Return to Index  

aspx thread: Checking for Null DataReader


Message #1 by "Hugh McLaughlin" <hugh@k...> on Thu, 13 Feb 2003 03:16:12
Hello Everyone and thanks for your help in advance.  I am setting up a 
forms validation module that performs a SQL Server lookup to validate 
user name and password.  Once the lookup has been accomplished, I use the 
following code:

        If Not IsDBNull(myReader) Then
            Return True
        Else
            Return False
        End If

However, for some reason, "True" is returned in all cases, including 
cases where I have verified that there are no matches.  I have verified 
this additionally by modifying the query to return a count.  I am really 
not sure why this ins't working.  Any help would be greatly appreciated.  
Thanks.
Message #2 by "Aaron Seet" <aspfriends@i...> on Thu, 13 Feb 2003 11:18:03 +0800
Wouldn't a count query return 0 if no records are found? Which is not the
same as NULL?

And how about simply:
Return(Not IsDBNull(myReader))


----- Original Message -----
From: "Hugh McLaughlin" <hugh@k...>
To: "ASP.NET" <aspx@p...>
Sent: Thursday, February 13, 2003 03:16
Subject: [aspx] Checking for Null DataReader


Hello Everyone and thanks for your help in advance.  I am setting up a
forms validation module that performs a SQL Server lookup to validate
user name and password.  Once the lookup has been accomplished, I use the
following code:

        If Not IsDBNull(myReader) Then
            Return True
        Else
            Return False
        End If

However, for some reason, "True" is returned in all cases, including
cases where I have verified that there are no matches.  I have verified
this additionally by modifying the query to return a count.  I am really
not sure why this ins't working.  Any help would be greatly appreciated.
Thanks.

Message #3 by "Pratap Ladhani" <pratapl@b...> on Thu, 13 Feb 2003 09:48:34 +0530
I guess this code snippet should work.

if myReader.read() then
	Return True
else
	Return False
end if
myReader.close()

Pratap Ladhani

-----Original Message-----
From: Aaron Seet [mailto:aspfriends@i...]
Sent: Thursday, February 13, 2003 8:48 AM
To: ASP.NET
Subject: [aspx] Re: Checking for Null DataReader


Wouldn't a count query return 0 if no records are found? Which is not the
same as NULL?

And how about simply:
Return(Not IsDBNull(myReader))


----- Original Message -----
From: "Hugh McLaughlin" <hugh@k...>
To: "ASP.NET" <aspx@p...>
Sent: Thursday, February 13, 2003 03:16
Subject: [aspx] Checking for Null DataReader


Hello Everyone and thanks for your help in advance.  I am setting up a
forms validation module that performs a SQL Server lookup to validate
user name and password.  Once the lookup has been accomplished, I use the
following code:

        If Not IsDBNull(myReader) Then
            Return True
        Else
            Return False
        End If

However, for some reason, "True" is returned in all cases, including
cases where I have verified that there are no matches.  I have verified
this additionally by modifying the query to return a count.  I am really
not sure why this ins't working.  Any help would be greatly appreciated.
Thanks.



Message #4 by "Hugh McLaughlin" <hugh@k...> on Thu, 13 Feb 2003 12:52:17
Thanks for your response and assistance.  Unfortuantely, this isn't 
working properly either.  Basically, what I am trying to do is see if a 
macthing record is returned and issue a validation ticket.  I can get it 
to work using a Count query and then checking to see if the count > 0.  
But what I would really like is to test to see if the reader is null.  It 
it is not, I want to perform further validation on the record before 
issuing the ticket.  The code you supplied, for some reason, only 
returns "Fasle".  Again, not sure why or what I am missing.

> I guess this code snippet should work.

if myReader.read() then
	Return True
else
	Return False
end if
myReader.close()

Pratap Ladhani

-----Original Message-----
From: Aaron Seet [mailto:aspfriends@i...]
Sent: Thursday, February 13, 2003 8:48 AM
To: ASP.NET
Subject: [aspx] Re: Checking for Null DataReader


Wouldn't a count query return 0 if no records are found? Which is not the
same as NULL?

And how about simply:
Return(Not IsDBNull(myReader))


----- Original Message -----
From: "Hugh McLaughlin" <hugh@k...>
To: "ASP.NET" <aspx@p...>
Sent: Thursday, February 13, 2003 03:16
Subject: [aspx] Checking for Null DataReader


Hello Everyone and thanks for your help in advance.  I am setting up a
forms validation module that performs a SQL Server lookup to validate
user name and password.  Once the lookup has been accomplished, I use the
following code:

        If Not IsDBNull(myReader) Then
            Return True
        Else
            Return False
        End If

However, for some reason, "True" is returned in all cases, including
cases where I have verified that there are no matches.  I have verified
this additionally by modifying the query to return a count.  I am really
not sure why this ins't working.  Any help would be greatly appreciated.
Thanks.



Message #5 by "Nebojsa Gogic" <ngogic@v...> on Thu, 13 Feb 2003 09:42:03 -0500
Did you try something like this:

try
{
    .
    .
    .
    reader.Read();
    .
    .
    .
    return(true);
}
catch
{
    return(false)
}

Anyway, I think your code should be: Return(Not IsDBNull(myReader("Column
Name"))), not Return(Not IsDBNull(myReader))

Nebojsa Gogic



----- Original Message -----
From: "Hugh McLaughlin" <hugh@k...>
To: "ASP.NET" <aspx@p...>
Sent: Thursday, February 13, 2003 12:52 PM
Subject: [aspx] Re: Checking for Null DataReader


> Thanks for your response and assistance.  Unfortuantely, this isn't
> working properly either.  Basically, what I am trying to do is see if a
> macthing record is returned and issue a validation ticket.  I can get it
> to work using a Count query and then checking to see if the count > 0.
> But what I would really like is to test to see if the reader is null.  It
> it is not, I want to perform further validation on the record before
> issuing the ticket.  The code you supplied, for some reason, only
> returns "Fasle".  Again, not sure why or what I am missing.
>
> > I guess this code snippet should work.
>
> if myReader.read() then
> Return True
> else
> Return False
> end if
> myReader.close()
>
> Pratap Ladhani
>
> -----Original Message-----
> From: Aaron Seet [mailto:aspfriends@i...]
> Sent: Thursday, February 13, 2003 8:48 AM
> To: ASP.NET
> Subject: [aspx] Re: Checking for Null DataReader
>
>
> Wouldn't a count query return 0 if no records are found? Which is not the
> same as NULL?
>
> And how about simply:
> Return(Not IsDBNull(myReader))
>
>
> ----- Original Message -----
> From: "Hugh McLaughlin" <hugh@k...>
> To: "ASP.NET" <aspx@p...>
> Sent: Thursday, February 13, 2003 03:16
> Subject: [aspx] Checking for Null DataReader
>
>
> Hello Everyone and thanks for your help in advance.  I am setting up a
> forms validation module that performs a SQL Server lookup to validate
> user name and password.  Once the lookup has been accomplished, I use the
> following code:
>
>         If Not IsDBNull(myReader) Then
>             Return True
>         Else
>             Return False
>         End If
>
> However, for some reason, "True" is returned in all cases, including
> cases where I have verified that there are no matches.  I have verified
> this additionally by modifying the query to return a count.  I am really
> not sure why this ins't working.  Any help would be greatly appreciated.
> Thanks.
>
>
>

Message #6 by "Aaron Seet" <aspfriends@i...> on Fri, 14 Feb 2003 10:33:12 +0800
So what you need is actually just a single value? Try ExecuteScalar() for
fast query.
http://www.learnasp.com/freebook/learn/executescalar.aspx


----- Original Message -----
From: "Hugh McLaughlin" <hugh@k...>
To: "ASP.NET" <aspx@p...>
Sent: Thursday, February 13, 2003 12:52
Subject: [aspx] Re: Checking for Null DataReader


Thanks for your response and assistance.  Unfortuantely, this isn't
working properly either.  Basically, what I am trying to do is see if a
macthing record is returned and issue a validation ticket.  I can get it
to work using a Count query and then checking to see if the count > 0.
But what I would really like is to test to see if the reader is null.  It
it is not, I want to perform further validation on the record before
issuing the ticket.  The code you supplied, for some reason, only
returns "Fasle".  Again, not sure why or what I am missing.

Message #7 by "Van Knowles" <vknowles@s...> on Wed, 19 Feb 2003 20:29:34
> So what you need is actually just a single value? Try ExecuteScalar() for
fast query.
http://www.learnasp.com/freebook/learn/executescalar.aspx


----- Original Message -----
From: "Hugh McLaughlin" <hugh@k...>
To: "ASP.NET" <aspx@p...>
Sent: Thursday, February 13, 2003 12:52
Subject: [aspx] Re: Checking for Null DataReader


Thanks for your response and assistance.  Unfortuantely, this isn't
working properly either.  Basically, what I am trying to do is see if a
macthing record is returned and issue a validation ticket.  I can get it
to work using a Count query and then checking to see if the count > 0.
But what I would really like is to test to see if the reader is null.  It
it is not, I want to perform further validation on the record before
issuing the ticket.  The code you supplied, for some reason, only
returns "Fasle".  Again, not sure why or what I am missing.

Message #8 by "Van Knowles" <vknowles@s...> on Wed, 19 Feb 2003 20:35:12
(Sorry about the previous reply - I hit Enter by mistake)

Okay, the first thing is:  when a datareader has no rows, it does not 
return null - it returns False (on the first read).

So, to find out whether you have data, you need to issue _one_ 
datareader.read() and test the boolean result.  Either:

if datareader.read() then ... end if

or

testvar=datareader.read()
if testvar then ... end if

If the result is True, then you may proceed to process the columns of the 
result set, as in:

cvar1=datareader("colname")

etc.


> So what you need is actually just a single value? Try ExecuteScalar() for
fast query.
http://www.learnasp.com/freebook/learn/executescalar.aspx


----- Original Message -----
From: "Hugh McLaughlin" <hugh@k...>
To: "ASP.NET" <aspx@p...>
Sent: Thursday, February 13, 2003 12:52
Subject: [aspx] Re: Checking for Null DataReader


Thanks for your response and assistance.  Unfortuantely, this isn't
working properly either.  Basically, what I am trying to do is see if a
macthing record is returned and issue a validation ticket.  I can get it
to work using a Count query and then checking to see if the count > 0.
But what I would really like is to test to see if the reader is null.  It
it is not, I want to perform further validation on the record before
issuing the ticket.  The code you supplied, for some reason, only
returns "Fasle".  Again, not sure why or what I am missing.

Message #9 by "Paul Riley" <rilez@t...> on Wed, 19 Feb 2003 20:23:03 -0000
Just use datareader.read - if it returns false then it's at the end /
empty. If you are however only after one value as Van was asking use
execute scalar - again checking for false iirc

Does that make things clearer?

-----Original Message-----
From: Van Knowles [mailto:vknowles@s...] 
Sent: 19 February 2003 20:30
To: ASP.NET
Subject: [aspx] Re: Checking for Null DataReader


> So what you need is actually just a single value? Try ExecuteScalar() 
> for
fast query. http://www.learnasp.com/freebook/learn/executescalar.aspx


----- Original Message -----
From: "Hugh McLaughlin" <hugh@k...>
To: "ASP.NET" <aspx@p...>
Sent: Thursday, February 13, 2003 12:52
Subject: [aspx] Re: Checking for Null DataReader


Thanks for your response and assistance.  Unfortuantely, this isn't
working properly either.  Basically, what I am trying to do is see if a
macthing record is returned and issue a validation ticket.  I can get it
to work using a Count query and then checking to see if the count > 0.
But what I would really like is to test to see if the reader is null.
It it is not, I want to perform further validation on the record before
issuing the ticket.  The code you supplied, for some reason, only
returns "Fasle".  Again, not sure why or what I am missing.



  Return to Index