Home Articles FAQs XREF Games Software Instant Books About Feedback Search Site-Map
irt.org logo

Q5822 How can I tell when my database query returns 0 records?

irt.org | Knowledge Base | ASP | Q5822 [ previous next ]

Q5822 How can I tell when my database query returns 0 records?

From time to time an application will execute a SQL query that's supposed to retrieve something, but doesn't. Whatever the underlying reason, it's important to handle this case.

You should always encapulsate any code that depends on data being returned in a control flow structure (see examples).

<%

' EXAMPLE 1
' LOOP THROUGH SOME RECORDS
' AND WRITE THEIR VALUES TO THE
' BROWSER.  The not RS.EOF MEANS
' NOT YET AT THE END OF FILE

do while not RS.EOF
  response.write RS("fieldName")
loop

' EXAMPLE 2

if RS.EOF then
  response.write "No records were returned"
else
  ' DO SOMETHING WITH THE RECORDS
end if

%>

Feedback on 'Q5822 How can I tell when my database query returns 0 records?'


Provide feedback ...
AddThis Social Bookmark Button

Provide feedback ... AddThis Social Bookmark Button


Last Updated: 30th March 2008. Maintained by: Martin Webb
irt.org liability, trademark, document use, privacy statement and software licensing rules apply.
Copyright © 1996-2008 irt.org, All Rights Reserved.