Click here to Skip to main content
15,891,473 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Everyone,

I'm using the database class from
http://www.codeproject.com/KB/database/csharpaccessdb.aspx
and for the most part it has worked exactly how I want, which is great.

I came across a problem when one of my queries uses the LIKE '*' condition. For some reason, whenever * is used, it doesn't work.

Let me give an example...
SELECT Title FROM Books WHERE Title LIKE 'Tomorrow, When The War Began';
WORKS in Access and C#

SELECT Title FROM Books WHERE Title LIKE 'Tomorrow*';
Works in Access, but not in C#

I can't seem to find out why the * doesn't work. I got to the stage where I was copying the query directly from a working Access query where it returns the correct results, but when I put it in C#, it just doesn't work. Every other query that doesn't involve LIKE '*' works in C# with the exact same results as Access, so there isn't a problem connecting to the database.

If there are any suggestions, that would be a great help!

Thanks,
Josh.
Posted

I dont what the code that builds the query looks like, but as a guess, just try using an @ before the string that contains 'Tomorrow*'.
 
Share this answer
 
v2
Hi Abhinav,

Thanks for your prompt reply. I looked around online for some more Access and SQL in C#, and found that if I used a % instead of a * in C# it will work. In Access, you can only use * as a wildcard (I will admit, normally using SQL Server I initially used % as a wildcard to find that it didn't work.)

A little bit annoying (as I normally write the queries in Access and then copy then over, need to remember to change all the wildcards now), but at least it's working now!

Again, thanks for your prompt reply.

Josh.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900