[web] ASP: What to do when query is empty

This topic is 4849 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

I have a pretty basic question in regards to queries on an ASP page. I have a record that is getting pulled from the database, but if there are no records it throws an error (no BOF or EOF). It would seem though that I cannot say 'if recordid = nothing then go to an error page', since it SEEMS to then be complaining that recordid does not exist. When making a query, and in the case there are no records to display, should there be anything special I should be doing in order to stop it throwing a server error?

Share on other sites
just check to see if there is a record before you try to use em.

if rst.EOF = false then
use record
else
do something else.
end if

if the data is all spread out and your no simply looping the recordset.

do the check to see if there are records and set a boolean flag on the results

then every place you use a record from the recordset do a check using the flag.

it could be your not actually creating the right objects mind.

post your code if you want.

Share on other sites
Generally when I get information in a recordset I loop through it like so:

while( NOT objRst.EOF )  'stuff - basically you do anything you want to the current row of the  ' recordset here, then the next iteration will take care of the next row,  ' and so on...  objRst.movenextwend

or when I'm really not expecting to use more than one record, I do something like:

if( NOT objRst.EOF ) then  'stuff to be done to current row in the recordsetend if

Hope that helps!

• 15
• 9
• 13
• 41
• 15