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
Solved

MS ACCESS and C# using LIKE OPERATOR

Posted on 2004-10-10
5
2,788 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
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: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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

In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
Familiarize people with the process of utilizing SQL Server stored procedures 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 Micr…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

839 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