Solved

MS ACCESS and C# using LIKE OPERATOR

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

[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
If you need a simple but flexible process for maintaining an audit trail of who created, edited, or deleted data from a table, or multiple tables, and you can do all of your work from within a form, this simple Audit Log will work for you.
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
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 …

627 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