Dynadot โ€” .com Registration $8.99

[Resolved] ASP for each loop with a database

Spaceship Spaceship
Watch

stscac

A Wealth of KnowledgeVIP Member
Impact
73
ASP for each loop with a database

Experimenting with ASP and need a little help with some ASP.

Here's what I have. It returns 6 rows of the same thing. What do I need to do differently?

Code:
set conn=Server.CreateObject("ADODB.Connection")
conn.Provider="Microsoft.Jet.OLEDB.4.0"
conn.Open "C:\Inetpub\wwwroot\IT-Site\db1.mdb"
set thistask = Server.CreateObject("ADODB.recordset")
thistask.Open "Select * FROM this_week_tasks", conn

for each x in thistask.fields
response.write("<tr>")
response.write("<td>")
tid = thistask.Fields.Item("TaskID")
response.write(tid)
response.write("</td>")
response.write("<td>")
act = thistask.Fields.Item("Activity")
response.write(act)
response.write("</td>")
response.write("<td>")
own = thistask.Fields.Item("Owner")
response.write(own)
response.write("</td>")
response.write("<td>")
tardate = thistask.Fields.Item("TargetDate")
response.write(tardate)
response.write("</td>")
response.write("<td>")
stat = thistask.Fields.Item("Status")
response.write(stat)
response.write("</td>")
response.write("</tr>")
next
%>
I am guessing that it has to do something with the recordset, but, being new to ASP, I have no idea.

-Steve
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
Actually you would need something like that (untested):
Code:
if thistask.bof and thistask.eof then
  response.write "recordset is empty"
else
   thistask.movefirst ' position to 1st record
   do ' begin loop

       ' do your repeat stuff here
       response.write thistask.Fields.Item("TaskID")

       thistask.movenext ' proceed with next record

    loop until thistask.eof ' loop until end of recordset
end if
 
1
•••
Are you trying to loop through records?
Your code is looping through fields!

To go to the next record you have to call "MoveNext" on your recordset.

Try:

Do While Not thistask.EOF

... code ...

thistask.movenext

Next
 
0
•••
sdsinc said:
Actually you would need something like that (untested):
Code:
if thistask.bof and thistask.eof then
  response.write "recordset is empty"
else
   thistask.movefirst ' position to 1st record
   do ' begin loop

       ' do your repeat stuff here
       response.write thistask.Fields.Item("TaskID")

       thistask.movenext ' proceed with next record

    loop until thistask.eof ' loop until end of recordset
end if
Works Perfectly! Thanks

-Steve
 
0
•••
Dynadot โ€” .com Registration $8.99Dynadot โ€” .com Registration $8.99
Unstoppable Domains
Domain Recover
DomainEasy โ€” Payment Flexibility
  • The sidebar remains visible by scrolling at a speed relative to the pageโ€™s height.
Back