easy syntax q: for each record in recordset

K

Ken Fine

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.
 
R

Ray at

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
 
P

Phill. W

Ken Fine said:
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.
 
R

Ray at

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 said:
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 said:
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.
 
B

Bob Barrows

Ken said:
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
 
K

Ken Fine

Exactly what I need. Thanks.

-KF


Phill. W said:
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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,479
Members
44,900
Latest member
Nell636132

Latest Threads

Top