msberth
asked on
ASP- SEARCHING FOR A RECORD IN AN MDB TABLE
I have an access database and a table called Items, so i wrote as asp program to search for records in this table, the program manages to retrieve all records,thus when the "search all fields"button is set to on, but when its not set to on,it gives the Error:
Syntax error (missing operator) in query expression 'ItemID '%7%' Or Item_name Like '%7%''.
/9905112/FINAL PROJECT2/searchitem.asp, line 45,
thus when i want to retrieve only one record. Can u help me on this error!
Code segement is as below:
srchval =Replace(Request.Form("src hval"),"'" ,"''")
srchall = Request.Form("srchall")
If srchall = "ON" Then
SQL = "Select * From Items"
Set RS = MyConn.Execute(SQL)
If RS.BOF And RS.EOF Then
Response.Write "No Records Found."
Else
%>
<p> </p>
<%
Response.Write "<center><table border=""1""><tr>"
For i = 0 To RS.Fields.Count - 1
Response.Write "<th>" & RS(i).name & "</th>"
Next
Response.Write "</tr>"
While Not RS.EOF
Response.Write "<tr>"
For i = 0 To RS.Fields.Count - 1
Response.Write "<td>" & RS(i).Value & "</td>"
Next
Response.Write "</tr>"
RS.MoveNext
Wend
Response.Write "</table>"
End If
Else
SQL = "Select * From Items Where ItemID '%"&srchval&"%'"
SQL = SQL & " Or Item_name Like '%"&srchval&"%'"
Set RS = MyConn.Execute(SQL)
If RS.BOF And RS.EOF Then
Response.Write "No Records Found."
Else
Response.write "Item ID or Name : "
Response.write srchval
%>
<p> </p>
<%
Response.Write "<center><table border=""1""><tr>"
For i = 0 To RS.Fields.Count - 1
Response.Write "<th>" & RS(i).name & "</th>"
Next
Response.Write "</tr>"
While Not RS.EOF
Response.Write "<tr>"
For i = 0 To RS.Fields.Count - 1
Response.Write "<td>" & RS(i).Value & "</td>"
Next
Response.Write "</tr>"
RS.MoveNext
Wend
Response.Write "</table>"
End If
End if
Syntax error (missing operator) in query expression 'ItemID '%7%' Or Item_name Like '%7%''.
/9905112/FINAL PROJECT2/searchitem.asp, line 45,
thus when i want to retrieve only one record. Can u help me on this error!
Code segement is as below:
srchval =Replace(Request.Form("src
srchall = Request.Form("srchall")
If srchall = "ON" Then
SQL = "Select * From Items"
Set RS = MyConn.Execute(SQL)
If RS.BOF And RS.EOF Then
Response.Write "No Records Found."
Else
%>
<p> </p>
<%
Response.Write "<center><table border=""1""><tr>"
For i = 0 To RS.Fields.Count - 1
Response.Write "<th>" & RS(i).name & "</th>"
Next
Response.Write "</tr>"
While Not RS.EOF
Response.Write "<tr>"
For i = 0 To RS.Fields.Count - 1
Response.Write "<td>" & RS(i).Value & "</td>"
Next
Response.Write "</tr>"
RS.MoveNext
Wend
Response.Write "</table>"
End If
Else
SQL = "Select * From Items Where ItemID '%"&srchval&"%'"
SQL = SQL & " Or Item_name Like '%"&srchval&"%'"
Set RS = MyConn.Execute(SQL)
If RS.BOF And RS.EOF Then
Response.Write "No Records Found."
Else
Response.write "Item ID or Name : "
Response.write srchval
%>
<p> </p>
<%
Response.Write "<center><table border=""1""><tr>"
For i = 0 To RS.Fields.Count - 1
Response.Write "<th>" & RS(i).name & "</th>"
Next
Response.Write "</tr>"
While Not RS.EOF
Response.Write "<tr>"
For i = 0 To RS.Fields.Count - 1
Response.Write "<td>" & RS(i).Value & "</td>"
Next
Response.Write "</tr>"
RS.MoveNext
Wend
Response.Write "</table>"
End If
End if
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SQL = "Select * From Items Where ItemID '%"&srchval&"%'" ------- In this
SQL = "Select * From Items Where ItemID like '%"&srchval&"%'"