Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP General > easy syntax q: for each record in recordset

Reply
Thread Tools

easy syntax q: for each record in recordset

 
 
Ken Fine
Guest
Posts: n/a
 
      11-28-2003
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.


 
Reply With Quote
 
 
 
 
Ray at
Guest
Posts: n/a
 
      11-28-2003
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" <(E-Mail Removed)> wrote in message
news:bq7u3i$eck$(E-Mail Removed)...
> 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.
>
>



 
Reply With Quote
 
 
 
 
Phill. W
Guest
Posts: n/a
 
      11-28-2003
"Ken Fine" <(E-Mail Removed)> wrote in message
news:bq7u3i$eck$(E-Mail Removed)...
> 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.


 
Reply With Quote
 
Ray at
Guest
Posts: n/a
 
      11-28-2003
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:%(E-Mail Removed)...
> 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" <(E-Mail Removed)> wrote in message
> news:bq7u3i$eck$(E-Mail Removed)...
> > 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.
> >
> >

>
>



 
Reply With Quote
 
Bob Barrows
Guest
Posts: n/a
 
      11-28-2003
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"


 
Reply With Quote
 
Ken Fine
Guest
Posts: n/a
 
      11-28-2003
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$(E-Mail Removed)...
> "Ken Fine" <(E-Mail Removed)> wrote in message
> news:bq7u3i$eck$(E-Mail Removed)...
> > 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.
>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
asp code does not render for first record in looped recordset haft@canchair.com ASP General 18 07-25-2008 08:21 AM
how do i? Full scan of each control in each grid row cell John Blair ASP .Net 1 08-03-2005 11:02 AM
Accessing an ADO Recordset or Record from ADO.NET nita ASP .Net 1 11-20-2004 07:06 AM
xsl:for-each for each 3 elements problem Tjerk Wolterink XML 3 11-03-2004 05:22 PM
RecordSet.Move or RecordSet.AbsolutePosition?? Hung Huynh ASP General 8 09-24-2003 11:07 AM



Advertisments