easy syntax q: for each record in recordset

Discussion in 'ASP General' started by Ken Fine, Nov 28, 2003.

  1. Ken Fine

    Ken Fine Guest

    Suppose I've built a recordset. I want some code to run for each record in
    the recordset in a "loop." In ASP VBScript, how would you express the
    following:

    For each [record] in [recordset]
    [run some code]
    next

    The only thing I'm really fuzzy on is the syntax for describing each
    recordset row. Thanks for any help.
     
    Ken Fine, Nov 28, 2003
    #1
    1. Advertising

  2. Ken Fine

    Ray at Guest

    Do While Not TheRecordset.EOF
    'run code, such as:
    response.write TheRecords.Fields.Item(0).Value & "<br>"
    Loop

    That is one way.

    Ray at work

    "Ken Fine" <> wrote in message
    news:bq7u3i$eck$...
    > Suppose I've built a recordset. I want some code to run for each record in
    > the recordset in a "loop." In ASP VBScript, how would you express the
    > following:
    >
    > For each [record] in [recordset]
    > [run some code]
    > next
    >
    > The only thing I'm really fuzzy on is the syntax for describing each
    > recordset row. Thanks for any help.
    >
    >
     
    Ray at, Nov 28, 2003
    #2
    1. Advertising

  3. Ken Fine

    Phill. W Guest

    "Ken Fine" <> wrote in message
    news:bq7u3i$eck$...
    > Suppose I've built a recordset. I want some code to run for each
    > record in the recordset in a "loop."


    rsData.Open( ...

    ' Depending on the recordset's options, you /might/ need
    rsData.MoveFirst

    ' Then, simply
    Do While Not rsData.EOF
    ' Do something useful with the "current" record
    Response.Write rsData.Fields( "PK1" ).Value & "<p>" ' say

    ' Get the next record
    rsData.MoveNext
    Loop

    HTH,
    Phill W.
     
    Phill. W, Nov 28, 2003
    #3
  4. Ken Fine

    Ray at Guest

    Ooops. That's an endless loop that I posted. I forgot a rather important
    part...

    Do While Not TheRecordset.EOF
    'run code, such as:
    response.write TheRecords.Fields.Item(0).Value & "<br>"
    THERECORDSET.MOVENEXT
    Loop

    Ray at work

    "Ray at <%=sLocation%>" <myfirstname at lane34 dot com> wrote in message
    news:%...
    > Do While Not TheRecordset.EOF
    > 'run code, such as:
    > response.write TheRecords.Fields.Item(0).Value & "<br>"
    > Loop
    >
    > That is one way.
    >
    > Ray at work
    >
    > "Ken Fine" <> wrote in message
    > news:bq7u3i$eck$...
    > > Suppose I've built a recordset. I want some code to run for each record

    in
    > > the recordset in a "loop." In ASP VBScript, how would you express the
    > > following:
    > >
    > > For each [record] in [recordset]
    > > [run some code]
    > > next
    > >
    > > The only thing I'm really fuzzy on is the syntax for describing each
    > > recordset row. Thanks for any help.
    > >
    > >

    >
    >
     
    Ray at, Nov 28, 2003
    #4
  5. Ken Fine

    Bob Barrows Guest

    Ken Fine wrote:
    > Suppose I've built a recordset. I want some code to run for each
    > record in the recordset in a "loop." In ASP VBScript, how would you
    > express the following:
    >
    > For each [record] in [recordset]
    > [run some code]
    > next
    >
    > The only thing I'm really fuzzy on is the syntax for describing each
    > recordset row. Thanks for any help.


    dim arData, rs, i
    'open the recordset then
    if not rs.EOF then arData = rs.GetRows
    rs.close: set rs = nothing
    'close and destroy the connection here as well
    for i = 0 to Ubound(arData,2)
    'do your stuff
    next

    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, Nov 28, 2003
    #5
  6. Ken Fine

    Ken Fine Guest

    Exactly what I need. Thanks.

    -KF


    "Phill. W" <P.A.Ward@o-p-e-n-.-a-c-.-u-k> wrote in message
    news:bq7vgs$1i$...
    > "Ken Fine" <> wrote in message
    > news:bq7u3i$eck$...
    > > Suppose I've built a recordset. I want some code to run for each
    > > record in the recordset in a "loop."

    >
    > rsData.Open( ...
    >
    > ' Depending on the recordset's options, you /might/ need
    > rsData.MoveFirst
    >
    > ' Then, simply
    > Do While Not rsData.EOF
    > ' Do something useful with the "current" record
    > Response.Write rsData.Fields( "PK1" ).Value & "<p>" ' say
    >
    > ' Get the next record
    > rsData.MoveNext
    > Loop
    >
    > HTH,
    > Phill W.
    >
    >
     
    Ken Fine, Nov 28, 2003
    #6
    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. Hazzard
    Replies:
    2
    Views:
    663
    Hazzard
    Apr 6, 2004
  2. nita
    Replies:
    1
    Views:
    888
    Saravana
    Nov 20, 2004
  3. Bruno Desthuilliers
    Replies:
    5
    Views:
    402
    Bruno Desthuilliers
    Aug 29, 2007
  4. Hung Huynh
    Replies:
    8
    Views:
    330
    Bob Barrows
    Sep 24, 2003
  5. Replies:
    18
    Views:
    327
    Dooza
    Jul 25, 2008
Loading...

Share This Page