469,616 Members | 1,792 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,616 developers. It's quick & easy.

easy syntax q: for each record in recordset

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.
Jul 19 '05 #1
5 19364
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" <ke*****@u.washington.edu> wrote in message
news:bq**********@nntp6.u.washington.edu...
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.

Jul 19 '05 #2
"Ken Fine" <ke*****@u.washington.edu> wrote in message
news:bq**********@nntp6.u.washington.edu...
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.
Jul 19 '05 #3
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:%2****************@TK2MSFTNGP11.phx.gbl...
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" <ke*****@u.washington.edu> wrote in message
news:bq**********@nntp6.u.washington.edu...
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.


Jul 19 '05 #4
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"
Jul 19 '05 #5
Exactly what I need. Thanks.

-KF
"Phill. W" <P.A.Ward@o-p-e-n-.-a-c-.-u-k> wrote in message
news:bq*********@yarrow.open.ac.uk...
"Ken Fine" <ke*****@u.washington.edu> wrote in message
news:bq**********@nntp6.u.washington.edu...
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.

Jul 19 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.