Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP General > Loop

Reply
 
 
John Smith
Guest
Posts: n/a
 
      10-20-2003
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.


 
Reply With Quote
 
 
 
 
Bob Barrows
Guest
Posts: n/a
 
      10-20-2003
John Smith wrote:
> 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.


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"


 
Reply With Quote
 
 
 
 
Jeff Cochran
Guest
Posts: n/a
 
      10-21-2003
On Mon, 20 Oct 2003 22:46:09 +0000 (UTC), "John Smith"
<(E-Mail Removed)> wrote:

>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 ?


Why not just do:

Do Until objRS.EOF OR count=10

Jeff
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Triple nested loop python (While loop insde of for loop inside ofwhile loop) Isaac Won Python 9 03-04-2013 10:08 AM
Getting a loop to activate a loop above it Byte Python 4 03-24-2006 03:04 AM
Condition outside loop or separate loop for different condition? - Java 12 06-15-2005 08:50 AM
while loop in a while loop Steven Java 5 03-30-2005 09:19 PM
Loop the loop... =?Utf-8?B?VGltOjouLg==?= ASP .Net 2 02-16-2005 12:21 PM



Advertisments