2013-02-23 65 views
1

我想驗證信息,而不切換頁面(在這種情況下,用戶名,如果找到用戶名,很好,填充文本框和動態創建一個表它的用戶名)。但是,我收到第75行的錯誤消息:創建一個表點擊一個按鈕與傳統的ASP

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

哪一條是75號線? – JohnFx 2013-02-23 05:03:02

回答

-2

意味着你還沒有關閉連接對象

頁面
+0

完全不相關的問題。 – 2013-02-25 08:06:26

1

當這種情況發生故障的最後嘗試set cn =Nothing

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

您的代碼嘗試在不打開記錄集的情況下訪問rs.eof。

rs.open放在該塊的外面。