从asp结果集中获取值

时间:2011-03-02 00:35:28

标签: asp-classic

在下面的asp页面中,我试图从结果集的第一行获取fullName属性。 (应该只有一行)这样做的正确方法是什么?

<%
set Y = server.CreateObject("ADODB.Connection")
X = "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ= " & Server.MapPath(".\account.mdb")
Y.open X

user=request.Form("username")
passwd=request.Form("pwd")
set userexsist=Y.Execute("select * from logintable where username='" & user & "'")
set useraccount=Y.Execute("select * from logintable where username='"& user & "' and passwd='" & passwd & "'")

if userexsist.eof then
    Response.Redirect("41697hw1noaccount.htm")
else 
if  useraccount.eof then
    Response.Redirect("41697hw1wrongpasswd.htm")
else
    Response.Write("<h1>Welcome, " & useraccount[0].fullName & "</h1>")
End if
end if


%>

错误发生在`useraccount [0] .fullName。

获取此信息的正确方法是什么?

感谢您的帮助!

1 个答案:

答案 0 :(得分:2)

这是你的代码,尽可能多的错误,我可以发现修复:

我测试了它,但没有使用Access数据库。

它应该可以工作,但我只掌握Classic ASP的工作知识。

<%

Set Conn = Server.CreateObject("ADODB.Connection")
Set RS = Server.CreateObject("ADODB.Recordset")
Set RS2 = Server.CreateObject("ADODB.Recordset")

Conn.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ= " & Server.MapPath(".\account.mdb")

user = Request.Form("username")
passwd = Request.Form("pwd")

RS.Open "select * from logintable where username='" & user & "'", Conn

if RS.eof then
    Response.Redirect("41697hw1noaccount.htm")
else
    RS2.Open "select * from logintable where username='" & user & "' and passwd='" & passwd & "'", Conn
    if RS2.eof then
        Response.Redirect("41697hw1wrongpasswd.htm")
    else
        Response.Write("<h1>Welcome, " & RS2("fullName") & "</h1>")
    end if
end if

%>