Here is the reply you got
Chuck Haeberle said:
I need an expression to search a SQL statement
(any type, SELECT INSERT UPDATE OR
DELETE) and find all single apostrophes which
should be replaced with a double apostrophe
without affecting the apostrophes used to delimit
the string values:
You can't do this unambiguously. Here, for example ...
SELECT x FROM y WHERE text='something' OR text='other'
.... OR might be part of one long string with apostrophes in it.
A better idea is to pass a set of parameters to your data layer class and
use them to replace simple placeholders for their locations in the query
string. That way, you know which parts are parameters and can deal with them
accordingly.
void ExecuteSQL(string strQuery, params string[] strParameters);
My example would then be written:
MyDataLayer.ExecuteSQL("SELECT x FROM y WHERE text='?' OR text='?'",
"something", "other");
.... or ...
MyDataLayer.ExecuteSQL("SELECT x FROM y WHERE text='?'", "something' OR
text='other");
P.