2014-02-11 133 views
-1

我想回响在我的数据库从表中的一些数据,发现这个代码:有人可以解释这个asp代码的工作原理吗?

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 

我测试了它和它的工作,但我不知道该怎么所有的语法手段并没有提供解释代码。有经验的人能帮助我吗?

回答

2

rs是一个记录集,表示数据库查询的结果。

do until ...循环通过在记录集中找到的所有行(即表用户)迭代(在movenext的帮助下)。

在找到的每个行上的下一个循环遍历在单个行中找到的所有字段,在这种情况下,它只是列名。

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 
+0

所以这个代码:'的Server.CreateObject(“ADODB.recordset”)',是我需要我想要得到的东西从数据库中每一次? –

+0

@Sir_Ivyk这和类似'Server.CreateObject(“ADODB.Connection”)',是的。 – gvee

+0

@gvee您可以通过查看[MSDN上的ADO API参考](http://msdn.microsoft.com/en-us/library/windows/desktop/ms678086(v = vs.85).aspx ) – Lankymart

相关问题