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

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...

-¿-
 
F

forest demon

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...

-¿-
 
A

Anders Borum

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top