I am trying to get some results from the database, but the query is failing!
String sqlFindModel = "SELECT * FROM [PRODUCT] WHERE [PN] LIKE ('*" + textBox1.Text + "*')";
When I trim the “WHERE [PN] LIKE …” part, it works fine.
When I replace LIKE to ‘=’ and look for Exact value, it works.
I am confused.
PS – It is Interesting, when doing Query in ACCESS directly, you have to use *; but when using C# and connect to MS Access, need to use %… interesting!
*isn’t used for wildcarding in SQL LIKE statements –%is.However, you shouldn’t just change your code to use
%– you should fix your code so it’s not vulnerable to SQL injection attacks, instead. You should use parameterized SQL instead. See the documentation forOleDbCommand.Parametersfor an example.