Tuesday, September 13, 2011

Access ... thanks Microsoft for another problem!

Today I have this funny problem which Access and OleDB gave me two different results for the same view.  After hours of puzzling, finally found out it is because of the wild card used in the LIKE clause.

The story as follow, I have a view in Access similar to the below

select * where code like '*fun*'

This works fine within Access, i.e. only result contains "fun" returned.  However, when I accessing this view within VisualStudio via OleDB, the conditional clause was ignored.  Since I am accessing the same view within the same Access database, it really puzzled me why the different results returned, especialy there was no errors returned.

Initially I thought it was because of caching, so I restarted my machine.  Run the query within Visual Studio after restart, same problem.

Then I removed the connection within Visual Studio and recreate it as I thought it may caused by wrong settings.  Again, same problem.

Finally, I  replaced the * with % as I would write my LIKE in standard SQL. Bingo, everything works as intended.

Thanks Microsoft.  Can you not try to be special and screw things up?!

No comments: