0

Here is a made up query

"select * from tbl where name like '@foo%'"
...
cmd.addparam(foo, bar) //not actual code

I get 0 results. I tried changing the where to name like @foo and wrote bar+"%" however i suspect that is incorrect (it should escape %?) and i got 0 rows yet again.

How do I like with parameters? My code actually uses dapper.net with mysql as its database.

1 Answers1

2

You need to construct your query as follows:

"select * from tbl where name like @foo"

then

cmd.addParam("@foo", bar + "%")
syed mohsin
  • 2,948
  • 2
  • 23
  • 47
  • ok so i was using the right code however i discover that when doing `/a%` it doesnt find my `/ab` strings. It looks like it doesnt like starting with `/` –  Nov 28 '12 at 20:35
  • @acidzombie24 no, your original code is looking for the literal starting "@foo"... Nothing to do with the value from the parameter – Marc Gravell Nov 28 '12 at 21:31
  • @MarcGravell: I see. I ended up going with http://stackoverflow.com/questions/13614291/how-do-i-escape-mysql-properly#comment18667746_13614291 is that correct? I believe it is. –  Nov 28 '12 at 21:43