Solved

MS ACCESS and C# using LIKE OPERATOR

Posted on 2004-10-10
5
2,834 Views
Last Modified: 2008-02-01
Im having a problem with the last apostrophe but when i run it it will not recognize it... here is my code and the error

case "Product Name":
this.oleDbSelectCommand1.CommandText =       
         "SELECT * FROM ProductDescription " +
         "WHERE ProductNames = LIKE'*" + txtProductSearch.Text + "*'";
                                     
break;

Syntax error (missing operator) in query expression 'ProductNames = LIKE'*bo*''.
0
Comment
Question by:HappieMartyr
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 44

Expert Comment

by:Arthur_Wood
ID: 12272946
change this:

WHERE ProductNames = LIKE'*" + txtProductSearch.Text + "*'";

to:

WHERE ProductNames = LIKE '*" + txtProductSearch.Text + "*'";

the single space between LIKE and '* is CRITICAL.

AW
0
 

Author Comment

by:HappieMartyr
ID: 12272960
I added the space but that did not help unfortunately it returns the same error...



Syntax error (missing operator) in query expression 'ProductNames = LIKE '*bo*''.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Data.OleDb.OleDbException: Syntax error (missing operator) in query expression 'ProductNames = LIKE '*bo*''.
0
 
LVL 11

Expert Comment

by:Jokra_the_Barbarian
ID: 12273363
You can't use "= LIKE". This should work:

"SELECT * FROM ProductDescription WHERE ProductNames LIKE '*" & txtProductSearch.Text & "*'"
0
 
LVL 8

Accepted Solution

by:
Benjamin_Luk earned 500 total points
ID: 12273437
That right you can not use "=" with "LIKE". Also,you can try following method:
case "Product Name":
this.oleDbSelectCommand1.CommandText =      
         "SELECT * FROM ProductDescription " +
         "WHERE instr(1,ProductNames ,'"& txtProductSearch.Text &"',1)>0 ; "
0
 

Author Comment

by:HappieMartyr
ID: 12273777
I took out the = sign and that stopped the error but it would not return any thing then even if I typed it in exactly...
I even put in a little test to see what was happening by changing the button and I was getting the correct input but it still didnt work....

case "Product Name":
      this.oleDbSelectCommand1.CommandText =       
           "SELECT * FROM ProductDescription " +
           "WHERE ProductNames LIKE '*" + txtProductSearch.Text + "*'";

      btnSearch.Text = txtProductSearch.Text;
break;

all though it took a few minor changes since im using C#(+ instead of & ) the in string command was exactly what i needed  THANK YOU SO MUCH

case "Product Name":
this.oleDbSelectCommand1.CommandText =      
         "SELECT * FROM ProductDescription " +
         "WHERE instr(1,ProductNames ,'" + txtProductSearch.Text + "',1)>0 ; "
 
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.

738 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