komquat Posted May 2, 2007 Share Posted May 2, 2007 I am looking at looping information pulled from a Access DBHow do I use the FOR EACH ... IN ... Also, I am looking for a more indepth coverage of ASP, any suggestions on sites.Thanks Link to comment Share on other sites More sharing options...
Yahweh Posted May 3, 2007 Share Posted May 3, 2007 I am looking at looping information pulled from a Access DBHow do I use the FOR EACH ... IN ... Also, I am looking for a more indepth coverage of ASP, any suggestions on sites.ThanksIts not very clear what you're trying to do. If you want to loop through your records in a database, do this:<% Dim conn, rs, sqlSet Conn = Server.CreateObject("ADODB.Connection")Set RS = Server.CreateObject("ADODB.Recordset")sql = "Select * from table"Conn.open some_connection_stringRS.Open sql, conn, 1, 1 Do until rs. eof response.write rs("field1") response.write rs("field2") response.write rs("field3") rs.movenext LoopRS.CloseConn.close %> That loops through all the rows in your table. You don't usually need a For Each unless you don't know the names of your columns.If you didn't know the names of your fields ahead of time, then you'd do something like this: <% Dim conn, rs, field sqlSet Conn = Server.CreateObject("ADODB.Connection")Set RS = Server.CreateObject("ADODB.Recordset")Set Field = Server.CreateObject("ADODB.Field")sql = "Select * from table"Conn.open some_connection_stringRS.Open sql, conn, 1, 1 Do until rs. eof for each field in rs.fields response.write field.name & ": " & field.value next rs.movenext LoopRS.CloseConn.close %> Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.