How can i escape special characters( % [ _ ) in an Access SQL statement?

  • Thread starter Thread starter forest demon
  • Start date Start date
F

forest demon

i need to escape characters, such as ( % and/or _ and/or [ ),
since i have database entries that have such characters in them.

the following piece works fine in an SQL statement (c#), but doesn't
return entries that have one of the above characters in the argument.

... like '%" + tbProduct.Text.Replace("'", "''") + "%' ...

thanks folks...

-¿-
 
dude! that's what i was looking for.

i can stack them like so if need be:
'%" + tbProduct.Text.Replace("'", "''").Replace("%", "[%]")
..Replace("[", "[[]") + "%'

that works fine for me now...

thanks man....i appreciate your input!

Hi,

Would doing a myString.Replace("X", "[X]") will work.

Joe
--
http://www.csharp-station.com


forest demon said:
i need to escape characters, such as ( % and/or _ and/or [ ),
since i have database entries that have such characters in them.

the following piece works fine in an SQL statement (c#), but doesn't
return entries that have one of the above characters in the argument.

... like '%" + tbProduct.Text.Replace("'", "''") + "%' ...

thanks folks...

-¿-
 
Hi!

It is a recommended practice to use @parameters to provide placeholders in
your Sql statements. Construct the Sql statement with parameters and assign
the values by mapping each value to the corresponding parameter. This has
the benefit of a much cleaner Sql statement and avoids potential code
injections.

Let me know if you need additional help on this.
 
Back
Top