PDA

View Full Version : Executing an SQL query within IF statements


Vimal
06-09-2003, 02:37 AM
Hi all,

I am getting some problems when I execute an sql query within different IF statements. However, when I remove the IF statements, my sql query is executed without any error. Can anyone help plz.

Here is my code:

sPath = Server.MapPath("reservedb.mdb")
strConn = "DRIVER=Microsoft Access Driver (*.mdb);DBQ=" & sPath
set conn = server.createobject("adodb.connection")
conn.open strConn

set connrcs = server.createobject("adodb.recordset")

If Request.form("D1") = Fiction Then
strSql = "select * from books where Fiction= ON"
End if

If Request.form("D1") = Romance Then
strSql = "select * from books where Romance= ON"
End if

If Request.form("D1") = Suspense Then
strSql = "select * from books where Suspense= ON"
End if

If Request.form("D1") = Autobiography Then
strSql = "select * from books where Autobiography= ON"
End if

Connrcs.CursorLocation = 3 'adUseClient
Connrcs.CursorType = 3 'adOpenStatic
Connrcs.ActiveConnection = Conn
Connrcs.Open strSQL

And here is the error that I get:

ADODB.Recordset error '800a0bb9'

The application is using arguments that are of the wrong type, are out of acceptable range, or are in conflict with one another.

/ereserve/result1.asp, line 66

jsawkang
06-09-2003, 03:01 AM
Try This.

sPath = Server.MapPath("reservedb.mdb")
strConn = "DRIVER=Microsoft Access Driver (*.mdb);DBQ=" & sPath
set conn = server.createobject("adodb.connection")
conn.open strConn

set connrcs = server.createobject("adodb.recordset")

If Request.form("D1") = Fiction Then
strSql = "select * from books where Fiction= ON"

ElseIf Request.form("D1") = Romance Then
strSql = "select * from books where Romance= ON"

ElseIf Request.form("D1") = Suspense Then
strSql = "select * from books where Suspense= ON"

ElseIf Request.form("D1") = Autobiography Then
strSql = "select * from books where Autobiography= ON"
End if

Connrcs.CursorLocation = 3 'adUseClient
Connrcs.CursorType = 3 'adOpenStatic
Connrcs.ActiveConnection = Conn
Connrcs.Open strSQL

jsawkang
06-09-2003, 03:03 AM
ignore the 1 i posted early. i think using only if should solved solved ur problem. have a try.

sPath = Server.MapPath("reservedb.mdb")
strConn = "DRIVER=Microsoft Access Driver (*.mdb);DBQ=" & sPath
set conn = server.createobject("adodb.connection")
conn.open strConn

set connrcs = server.createobject("adodb.recordset")

If Request.form("D1") = Fiction Then
strSql = "select * from books where Fiction= ON"

ElseIf Request.form("D1") = Romance Then
strSql = "select * from books where Romance= ON"

ElseIf Request.form("D1") = Suspense Then
strSql = "select * from books where Suspense= ON"

Else
strSql = "select * from books where Autobiography= ON"
End if

Connrcs.CursorLocation = 3 'adUseClient
Connrcs.CursorType = 3 'adOpenStatic
Connrcs.ActiveConnection = Conn
Connrcs.Open strSQL

Vimal
06-09-2003, 04:09 AM
Still getting the same error message:

ADODB.Recordset error '800a0bb9'

The application is using arguments that are of the wrong type, are out of acceptable range, or are in conflict with one another.

/ereserve/result1.asp, line 67

jsawkang
06-09-2003, 07:24 AM
try this

If Request.form("D1") = "Fiction" Then
strSql = "select * from books where Fiction= 'ON'"

ElseIf Request.form("D1") = "Romance" Then
strSql = "select * from books where Romance= 'ON'"

ElseIf Request.form("D1") = "Suspense" Then
strSql = "select * from books where Suspense= 'ON'"

Else
strSql = "select * from books where Autobiography= 'ON'"
End if