[Resolved] ASP for each loop with a database

SpaceshipSpaceship
SpaceshipSpaceship
Namecheap AuctionsNamecheap Auctions
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
Close
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
Close
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
Close
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
Close
DomainEasy: flexible LTO options. Close more domain deals with financing.

We're social

Escrow.com
Spaceship
Domain Recover
CryptoExchange.com

NamePros updates

A browser tab with a favicon next to the page title
Search members
You can now search for members by name, company, location and more. Open the search at the top of any page and choose Members. You will...
AIVikings
Catchy
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back