NCS Logo - Click for home page Northstar Developer Center
Platforms
All Platforms
.NET Framework (1.x - 4.x)
Active Server Pages
ASP.NET
C#
SQL Server
VB.NET
Visual Basic

Keywords
.NET Data Types
.NET E-mail
.NET Events
.NET Functions
.NET Object Programming
.NET System.Configuration
.NET System.Diagnostics
.NET System.IO
.NET System.Net
.NET System.Net.Sockets
Active Data Objects
ASP Architecture
ASP Black Belt
ASP Built-in Functions
ASP Built-in Objects
ASP Debugging
ASP Performance
ASP Security
ASP Syntax
ASP.NET Authentication
ASP.NET Controls
ASP.NET Data Access
ASP.NET Features
ASP.NET Master Pages
ASP.NET Page Events
ASP.NET Security
ASP.NET ViewState
Atom
Certifications
COM, DCOM, COM+
Data Access
E-Mail
Errors
Exporting Data
HTML Tips
IIS
Object-Oriented Programming
RSS
SQL
Uncategorized ASP Tips
VB API Programming
VB Forms
VB Syntax
XML

Book Support
Visual Basic 6 Bible
ASP Bible
ASP Weekend Crash Course
ASP.NET At Work
Creating Web Services

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