This topic is locked

Error on Filter

2/29/2004 5:09:41 AM
ASPRunnerPro General questions
author

Can anyone see why I keep geting an error in the strSql=/rs.open area that says that it cannot do the operation because the recordset is closed? I am trying to test when the user chooses a menu item if the user has records in that area. If they don't then I want them to stay out until they do. Thanks... Bandit
Here is my code:
// By Bandit 2/28/2004
<!--#include file="include/dbconnection.asp"-->
<%

' filter user

username=Session("User")
' open database connection

Set rs = server.CreateObject ("ADODB.Recordset")

set dbConnection = server.CreateObject ("ADODB.Connection")

dbConnection.ConnectionString = strConnection

dbConnection.Open

' set SQL statement

strSQL = "Select Count(*) From Locations where MR= ' & username & ' "

rs.Open strSQL

' execute SQL statement

dbConnection.Execute strSQL

' run test

if rs.EOF then

%>

<script>

alert('No locations have been assigned to you. Please contact the office.');

</script>

<%

else

response.redirect "locations_list.asp"

end if

' close recordset and database connection

rs.close

dbConnection.close

%>
// End Bandit's Code

Sergey Kornilov admin 2/29/2004

I guess you missing double quotes here:

strSQL = "Select Count(*) From Locations where MR= ' & username & ' "


try this:

strSQL = "Select Count(*) From Locations where MR= '" & username & "' "