Solved

ASP- SEARCHING FOR  A RECORD IN AN MDB TABLE

Posted on 2004-03-29
2
276 Views
Last Modified: 2010-04-17
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("srchval"),"'","''")
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>&nbsp;</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>&nbsp;</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
0
Comment
Question by:msberth
  • 2
2 Comments
 
LVL 7

Expert Comment

by:ramesh12
ID: 10709980
Missing like operator

SQL = "Select * From Items Where ItemID '%"&srchval&"%'"     ------- In this




SQL = "Select * From Items Where ItemID like '%"&srchval&"%'"

0
 
LVL 7

Accepted Solution

by:
ramesh12 earned 25 total points
ID: 10710806
Moreover dont keep & like that there should be some space like this

SQL = "Select * From Items Where ItemID like '%" & srchval & "%'"
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
groupNoAdj 7 95
Image decoding from Camera 3 86
Base1 Encode/Decode 3 77
VbScript to countdown to New Year's Day 6 54
Here we come across an interesting topic of coding guidelines while designing automation test scripts. The scope of this article will not be limited to QTP but to an overall extent of using VB Scripting for automation projects. Introduction Now…
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question