Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

MS ACCESS and C# using LIKE OPERATOR

Posted on 2004-10-10
5
Medium Priority
?
2,959 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 2000 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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

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…
Code that checks the QuickBooks schema table for non-updateable fields and then disables those controls on a form so users don't try to update them.
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

876 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