All pastes #741269 Raw Edit

Untitled

public text v1 · immutable
·published 2007-10-18 16:04 UTC
rendered paste body
I have problem with filtering database with LIKE statement. In query i'm doing this:

...
WHERE z_zrealizowane=@z_zrealizowane AND (ze_nazwa LIKE @ze_nazwa ESCAPE '\' OR ze_typ_el LIKE @ze_nazwa ESCAPE '\')

and in program for @ze_nazwa i'm inserting this string:
string elementFiltr = "%" + (new Regex(@"([\\%_])")).Replace(this.elementTextBox.Text, @"\$1") + "%";

Regex.Replace is working just beautiful! but SELECT returns me like there was no LIKE!

i was thinking that maybe '\' is parsed wrong because it is common escape character and could be somewhere parsed twice for example, but..

another character for escape character is not working too:) e.g.:

...
WHERE z_zrealizowane=@z_zrealizowane AND (ze_nazwa LIKE @ze_nazwa ESCAPE '!' OR ze_typ_el LIKE @ze_nazwa ESCAPE '!')
and in program:
string elementFiltr = "%" + (new Regex(@"([!%_])")).Replace(this.elementTextBox.Text, @"!$1") + "%";

In two examples above Regex.Replace is working good. Can someone point me where i am wrong or how to use '@' and '_' characters in LIKE syntax?