Blog : ASP sql select statement

I'm getting this error
 Microsoft OLE DB Provider for ODBC Drivers (0x80040E14)
[Microsoft][ODBC Microsoft Access Driver] Syntax error (missing operator) in query expression 'questionNo ='.
/mmtec/mm32/quiz3.asp, line 12

when I do this
%
Set MyConn = Server.CreateObject("ADODB.Connection")
Set Rs=Server.CreateObject("ADODB.RecordSet")
MyConn.Open("mm32")
'now start the main loop to find all the questions
Rs.Open "SELECT * FROM Question WHERE questionNo=" & Request.QueryString("questionNo") , MyConn, 1, 2
if not Rs.EOF then
 Rs.movefirst
 do
 response.write "<b>" & Rs("questionNo") & ". " & Rs("questionText") & "</b><p>"
 'now display the available options

 Rs.Open "SELECT * FROM PossibleAnswer WHERE questionNo=" & Rs("questionNo"),MyConn, 1, 2
 if not Rs.EOF then
 Rs.movefirst
 do
 response.write Rs("answerText") & "<br>"
 Rs.movenext
 loop until Rs.EOF
 end if
 response.write "<p>"
 Rs.movenext
 loop until Rs.EOF
end if
Rs.Close
Myconn.close
%>
Any ideas gratefully received

Are you sure that your QueryString contains a decent value? From the error message, it appears that Request.QueryString("questionNo") is empty.

To find out, make a change to your code like this: (it's generally a good idea to create a separate variable for your SQL statement, so it's easier to debug):

Code:
Dim SQL
SQL = "SELECT * FROM Question WHERE questionNo=" & Request.QueryString("questionNo")

Response.Write("SQL is " & SQL)
Response.End

Rs.Open SQL , MyConn, 1, 2
Once you have written the SQL statement to the browser, I am almost sure you can see the problem. If you have fixed it, you can remove the .Write and .End lines again.

If the problem cannot be fixed, post the outcome of the .Write statement to this list so we can take a look at it.

By the way, I'm trying to synchronise 2 combo boxes.the first combo box has a list of laws from a table in a database called Law and the second combo box has a list of lawSubsections.When a user clicks , say, Law#1 , I want only those subsections that go with law#! to appear in the second combo box.There are already some pieces of info on this in the farest reaches of the web but unfortuneately theye are very fragmantary.Do I need 2 select statements in the same .asp file?
Actually the way I am doing it I am getting the same mistake I got previosly which is Microsoft OLE DB Provider for ODBC Drivers (0x80040E14)
[Microsoft][ODBC Microsoft Access Driver] Syntax error (missing operator) in query expression 'lawNo ='.

here is my code :
<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<%
 Option Explicit
 Dim MyConn, Rs, MyLaw , Rs2 , MyComponent
 Set MyConn=Server.CreateObject("ADODB.Connection")
 Set Rs=Server.CreateObject("ADODB.RecordSet")
 MyConn.Open("mm32")
 Rs.Open "SELECT * From Law", MyConn, 1, 2
 Set Rs2=Server.CreateObject("ADODB.RecordSet")
 Rs2.Open "SELECT * From Component where lawNo=" & Request.QueryString("lawNo"), MyConn, 1, 2
%>

<html>
<head>
<title>Inputting a new Question</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<SCRIPT Language="JavaScript">
 function mySubmit()
 {

 }


</SCRIPT>
</head>

<body>
<div align="center">
 <p><strong>Please use this form to input a new question </strong></p>



 <form name="form1" method="post" action="http://pertinax.cms.shu.ac.uk/mmtec/mm32/HandleInputQ.asp"">
 <p><strong>Choose a Law</strong>
 <select name="select">
 <%
 While NOT Rs.EOF
 MyLaw=Rs("lawNo") & " " & Rs("lawText")
%>
 <option value=<%=MyLaw%>><%=MyLaw%></option>
 <%
 Rs.MoveNext
 WEND
%>
 </select>
 </p>

 <p><strong>Which component of this law does your question most go with?</strong>
 <select name="select">
 <%
 While NOT Rs2.EOF
 MyComponent=Rs2("componentNo")
%>
 <option value=<%=MyComponent%>><%=MyComponent%></option>
 <%
 Rs2.MoveNext
 WEND
%>
 </select>
 </p>

 <p>
 <input type="submit" name="Submit" value="Submit" onClick="mySubmit()">
 </p>
 </form>
 <p><strong></strong> </p>
</div>
</body>