Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Like condition is not working properly

C# windows form :-> Database : Access

I have made a query somewhat like this

Select * from Emp where E_Name Like 'Alok*??????'

the above query is for getting records that have Alok and 6 charachter in their name.

If I execute this query in access it works fine and fetches the record but when I try it in c#

Select * from Emp where E_Name Like 'Alok*??????'

Or

Select * from Emp where E_Name Like 'Alok%??????'

Both of them does not work and i have also tried both type of connection string

Microsoft.ACE.OLEDB.12.0;

And

Microsoft.Jet.OLEDB.4.0;

How to solve this problem?

like image 686
Agent_Spock Avatar asked Sep 30 '22 21:09

Agent_Spock


1 Answers

You have this query which works in an Access session ...

Select * from Emp where E_Name Like 'Alok*??????'

When you want a similar query which you run from outside Access using OleDb, change the wild card characters ...

Select * from Emp where E_Name Like 'Alok%______'

But if you actually want only Alok followed by exactly 6 characters, use this instead ...

Select * from Emp where E_Name Like 'Alok______'
like image 104
HansUp Avatar answered Oct 06 '22 18:10

HansUp