我想从我的数据库中的表中回显一些数据并找到这段代码:
set rs = Server.CreateObject("ADODB.recordset")
rs.Open "Select name From users", conn
do until rs.EOF
for each x in rs.Fields
Response.Write(x.value)
next
rs.MoveNext
loop
rs.close
我测试了它并且它有效但我不知道所有语法的含义并且代码没有提供解释。有经验的人可以帮助我吗?
答案 0 :(得分:2)
rs是一个记录集,表示数据库查询的结果。
do until ...循环(在movenext的帮助下)遍历记录集中的所有行(即表用户)。
在所有行中找到for each ... next遍历单行中找到的所有字段,在这种情况下只是列名。
答案 1 :(得分:0)
请参阅以下代码中添加的评论
' Create a recordset. This is an object that can hold the results of a query.
set rs = Server.CreateObject("ADODB.recordset")
' Open the recordset for the query specified, using the connection "conn"
rs.Open "Select name From users", conn
' Loop over the results of the query until End Of File (EOF)
' i.e. move one at a time through the records until there are no more left
do until rs.EOF
' For each field in this record
for each x in rs.Fields
' Write out its value to screen
Response.Write(x.value)
' Move to the next field
next
' Move to the next record
rs.MoveNext
' Continue to loop until EOF
loop
' Close the recordset
rs.close