No one has picked this up, so I worked out a solution. There is a very useful “.Replace” method for strings which replaces all instances of a character eg \ or “. The code is correspondingly simple and short. You have to decide what characters to substitute for your naughty ones. I picked the “Thorn” character and the “Pilcrow” character.
See http://www.alanwood.net/demos/ansi.html
[code]
//Search for and replace characters in user input string that create errors in
//an SQL Update query. Replace Quote mark with Thorn character.
//Replace Backslash with Pilcrow character
private string ParseInput(string UserInput)
{
string sub1 = "\u00DE"; string sub2 = "\u00B6";
string search1 = "\""; string search2 = "\\";
string NewString = UserInput.Replace(search1,sub1);//Replace ALL quote marks
NewString = NewString.Replace(search2,sub2);//Replace ALL backslash characters
return NewString;
}
[\code]
There is a corresponding “inverseParse” method when reading from the database.