Every time i try to insert a string which contains a single quote I get a nasty error message.
How do you guys get around this ?
Do I have to write code to find and replace or is there another way ?
Printable View
Every time i try to insert a string which contains a single quote I get a nasty error message.
How do you guys get around this ?
Do I have to write code to find and replace or is there another way ?
A single quote is a special character in most DBMS. You have to, and should, excape all DB related special characters in any data you plan to UPDATE or INSERT.
If you are using MySQL, here is a string reference for special characters: http://www.mysql.com/doc/en/String_syntax.html
The single quote also applies to other DBMS such as MS Acces, MS SQL Server, Oracle, etc.. Look in their references guides.
A simple find and replace would do just wonderful.
Code:newstr = Replace(datatobeinserted, "'", "''")
'-In other words,
newstr = Replace(datadobeinserted, Chr(34), Chr(34) & Chr(34))
Hope I have helped.