Solved

MS ACCESS and C# using LIKE OPERATOR

Posted on 2004-10-10
5
2,718 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

Get up to 2TB FREE CLOUD per backup license!

An exclusive Black Friday offer just for Expert Exchange audience! Buy any of our top-rated backup solutions & get up to 2TB free cloud per system! Perform local & cloud backup in the same step, and restore instantly—anytime, anywhere. Grab this deal now before it disappears!

Join & Write a Comment

In Debugging – Part 1, you learned the basics of the debugging process. You learned how to avoid bugs, as well as how to utilize the Immediate window in the debugging process. This article takes things to the next level by showing you how you can us…
Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.

744 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

8 Experts available now in Live!

Get 1:1 Help Now