Solved

ASP- SEARCHING FOR  A RECORD IN AN MDB TABLE

Posted on 2004-03-29
2
265 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
Comment Utility
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
Comment Utility
Moreover dont keep & like that there should be some space like this

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

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Displaying an arrayList in a listView using the default adapter is rarely the best solution. To get full control of your display data, and to be able to refresh it after editing, requires the use of a custom adapter.
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

728 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now