Solved

Do until EOF or a specific number of times

Posted on 2004-08-09
5
1,085 Views
Last Modified: 2008-01-09
I would like to know how to do a loop in asp so that it would retrive files until the EOF OR to lets say 5.

So if there are 3 records in the db it will only retrive 3 records from the db
or if there are 10 records in the db it will only retrive 5 records from the db
0
Comment
Question by:quest_capital
5 Comments
 
LVL 15

Expert Comment

by:joeposter649
ID: 11756606
The best way would be to change the SQL to limit the results.  Depending on the DB you would use something like "rownum" or "top" to get the first 5 records.
0
 
LVL 3

Expert Comment

by:dwaldner
ID: 11756640
in vbscript:

while (condition here)
  (code lines)
wend

example for cycling through a recordset object (rs):

counter = 0
while not rs.eof
  counter = counter + 1
  rs.moveNext
wend
0
 
LVL 4

Expert Comment

by:tenacium
ID: 11756871
Without focusing too much on syntax, you could do something like:

Select count(*) from table

Then, set the result to a variable "x".

Select case x

Case x < 5
  y = "Select * From"
Case x > 5
  y = "Select TOP 3 From"

End Select

Then build your SQL query using the variable "y".
0
 
LVL 3

Accepted Solution

by:
hyperslug earned 125 total points
ID: 11757079
Dim MaxRecs : MaxRecs = 5

while not rs.eof and MaxRecs > 0
    ' do whatever
    MaxRecs = MaxRecs - 1
    rs.movenext
wend
0
 
LVL 15

Expert Comment

by:joeposter649
ID: 11762619
That won't "only retrive 5 records from the db".
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now