Limiting Results
Written by Eric Smith, Northstar Computer Systems LLC
A user asked how to limit the results from a database query to say, 100 records. There are a couple of ways to do this. The first is to use the SELECT COUNT feature of SQL to determine the total number of records that will be returned based on a set of criteria. If the result is over 100, you could inform the user that the query can't be run. If it's under 100, you show the results.
Another alternative is to get all the records and only allow the user to see the first 100. As you're looping through the recordset, keep a counter going and exit your loop if you pass 100. ADO is smart enough to only get data as it needs it, especially in forward-only recordsets, so you're not really getting all the data.
My favorite way is not to limit the results, but to provide a paging mechanism for the user that allows him to see all the results that came back. Limiting the results to 100 doesn't really help the user, especially if it takes a while to download those 100 results. It would be more user-friendly to show 20 results on a page, but let the user see 10 different pages.
Keywords: [
Uncategorized ASP Tips
]
Publication Date: 7/14/2000
|