Loop

Discussion in 'ASP General' started by John Smith, Oct 20, 2003.

  1. John Smith

    John Smith Guest

    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.
     
    John Smith, Oct 20, 2003
    #1
    1. Advertising

  2. John Smith

    Bob Barrows Guest

    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"
     
    Bob Barrows, Oct 21, 2003
    #2
    1. Advertising

  3. John Smith

    Jeff Cochran Guest

    On Mon, 20 Oct 2003 22:46:09 +0000 (UTC), "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 ?


    Why not just do:

    Do Until objRS.EOF OR count=10

    Jeff
     
    Jeff Cochran, Oct 21, 2003
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?VGltOjouLg==?=

    Loop the loop...

    =?Utf-8?B?VGltOjouLg==?=, Feb 16, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    1,386
    Karl Seguin
    Feb 16, 2005
  2. Steven

    while loop in a while loop

    Steven, Mar 24, 2005, in forum: Java
    Replies:
    5
    Views:
    2,242
    Tim Slattery
    Mar 30, 2005
  3. -
    Replies:
    12
    Views:
    698
    Remon van Vliet
    Jun 15, 2005
  4. Byte
    Replies:
    4
    Views:
    417
  5. Isaac Won
    Replies:
    9
    Views:
    390
    Ulrich Eckhardt
    Mar 4, 2013
Loading...

Share This Page