开发者

get value from asp result set

In the following asp page I am trying to get the fullName attribute from the first row of the result set. (there should only be one row) What is the right way to do this?

<%
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=开发者_如何学GoY.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


%>

The error is on `useraccount[0].fullName.

Whats the right way to get this information?

Thanks for your help!


Here's your code with as much wrong stuff as I could spot fixed:

I did test it, but not with an Access database.

It should work, but I only have a working knowledge of 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

%>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜