364,032 Members | 4260 Browsing Online
Community for Developers & IT Professionals
Bytes IT Community

Loop

John Smith
P: n/a
John Smith
I'm trying to perform a loop to display the contents of my DB, the only
issue is that I would only like to display 10 results maximum this is
relatively easy but what happens if there are less than 10 results in the
DB. If I was going to do a :

Do Until objRS.EOF

Then it would display the full records, likewise if i put a counter on the
loop then it will run into errors if I have less records than the
count.......

ideas ?

thanks.


Jul 19 '05 #1
Share this Question
Share on Google+
2 Replies


Bob Barrows
P: n/a
Bob Barrows
John Smith wrote:[color=blue]
> I'm trying to perform a loop to display the contents of my DB, the
> only issue is that I would only like to display 10 results maximum
> this is relatively easy but what happens if there are less than 10
> results in the DB. If I was going to do a :
>
> Do Until objRS.EOF
>
> Then it would display the full records, likewise if i put a counter
> on the loop then it will run into errors if I have less records than
> the count.......
>
> ideas ?
>
> thanks.[/color]

What database?
With Access and SQL Server, you can use the TOP n construct in your query to
limit the records returned (SELECT TOP 10 <field list> FROM table ...). With
SQL Server, you can also use SET ROWCOUNT to do the same thing.

If you have an antique database that does not support TOP, then simply
combine your counter idea with your DO loop:

dim i
i = 0
Do Until rs.eof OR i = 10
....
i = i + 1
rs.movenext
loop

HTH,
Bob Barrows

--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"


Jul 19 '05 #2

Jeff Cochran
P: n/a
Jeff Cochran
On Mon, 20 Oct 2003 22:46:09 +0000 (UTC), "John Smith"
<john@smith.smith> wrote:
[color=blue]
>I'm trying to perform a loop to display the contents of my DB, the only
>issue is that I would only like to display 10 results maximum this is
>relatively easy but what happens if there are less than 10 results in the
>DB. If I was going to do a :
>
>Do Until objRS.EOF
>
>Then it would display the full records, likewise if i put a counter on the
>loop then it will run into errors if I have less records than the
>count.......
>
>ideas ?[/color]

Why not just do:

Do Until objRS.EOF OR count=10

Jeff
Jul 19 '05 #3

Post your reply

Help answer this question



Didn't find the answer to your ASP / Active Server Pages question?

You can also browse similar questions: ASP / Active Server Pages