在经典的asp中使用记录集

时间:2013-04-14 04:53:49

标签: asp-classic recordset

我正在尝试使用记录集从数据库中获取数据,并使用经典ASP中的以下代码。我正在使用Windows 7 32位操作系统:

<%
dim con,rs
set con=Server.Createobject("ADODB.Connection")
con.Provider="Microsoft.Jet.OLEDB.4.0"
con.Open "c:\inetpub\wwwroot\New folder\123.mdb"
rs.Open "select * from student",con
for each x in rs.fields
response.write(x.name)
response.write("=")
response.write(x.value)
next
rs.Close
con.Close
%>

错误是:

Microsoft VBScript runtime error '800a01a8'

Object required: ''

/New folder/recordset.asp, line 7

1 个答案:

答案 0 :(得分:9)

VBScript中没有保留“rs”这个词,你必须自己创建一个记录集。

更改行:

rs.Open "select * from student",con

改为:

Set rs = con.Execute("select * from student")

您还只迭代第一条记录,迭代所有记录,将代码更改为:

Do Until rs.EOF
    for each x in rs.fields
        response.write(x.name)
        response.write("=")
        response.write(x.value)
        response.write(", ")
    next
    response.write("<br />")
    rs.MoveNext
Loop