单击带有经典asp的按钮创建表

时间:2013-02-23 02:51:25

标签: asp-classic adodb

我正在尝试验证信息,而不切换页面(在这种情况下是用户名,如果找到用户名,很棒,填充文本框并动态创建一个包含用户名的表)。但是,我在第75行收到的错误是:

ADODB.Recordset

 error '800a0e78' 

Operation is not allowed when the object is closed. 

/login.asp, line 75

我没有在任何地方关闭记录集。据我所知,它应该工作。我做错了什么?

<%
Dim cn,rs
    Set cn = Server.CreateObject("ADODB.Connection")
    Set rs = Server.CreateObject("ADODB.recordset")

    cn.Provider = "Microsoft.Jet.OLEDB.4.0"

    cn.Open Server.MapPath("login.mdb")

'Default message for the user on the login page
msg = "Please login"

'Logout code. This code empties the session variable which holds the user's userID.
If Request.QueryString("action") = "logout" Then
    Session("user_id") = ""
    msg = "You have been logged out"
End If


'Check if the form has been submitted

If Request.Form("Submit") = "Test" Then

    user_name = Request.Form("user_name")
    user_pass = Request.Form("user_pass")

    mySQL = "SELECT user_id, user_name, user_pass FROM users WHERE user_name = '" & user_name & "' AND user_pass = '" & user_pass & "'"

    'Select the data from the database using the submitted data.
    rs.Open mySQL, cn

        'Check if a match was found.
        If NOT rs.EOF Then

            'Session("user_id") = rsLogin("user_id")
            'Response.Redirect("profile.asp")

            u = rs("user_name")

        Else
            'If a match was not found then output an error.
            Response.Redirect("login.asp?errmsg=Login failed")
        End If
End If
%>



<!DOCTYPE html>
<html>
<head>
</head>

<body>
<form name="form1" id="form1" method="post" action="">
  <table width="300" border="0" cellspacing="0" cellpadding="2">
    <tr>
      <td>Username</td>
      <td><input name="user_name" type="text" id="user_name" /></td>
    </tr>
    <tr>
      <td>Password</td>
      <td><input name="user_pass" type="password" id="user_pass" /></td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td><input type="submit" name="Submit" value="Test" /></td>
    </tr>
  </table>
</form>
<input id="fileno" value="<%=u%>" type="text">


<%
        While NOT rs.EOF
%>
    <table width="200" border="1" cellspacing="0" cellpadding="2">
  <tr>
    <th scope="col"><div align="left">username</div></th>
  </tr>

  <tr>
    <td><%=u%></td>
  </tr>
<%
        rs.MoveNext
        Wend
%>
</table>
</body>
</html>

2 个答案:

答案 0 :(得分:1)

当这种情况失败时。

If Request.Form("Submit") = "Test" 

您的代码尝试在不打开记录集的情况下访问rs.eof。

放置该块的rs.open OUTSIDE。

答案 1 :(得分:-2)

表示您尚未关闭连接对象
 在页面末尾尝试set cn =Nothing