Replace " ' " symbol in my code
-
Hello All, I have a validation, replacing quotation mark in my dll as soon as surname or first name has been passed from my form. The code is : CStr(Replace(Trim(surname), " ' ", "$0")) The problem is when I type a surname = "O'Brian" the data does not go to the database and has internal server error. Can anybody suggest any other way I can liminate this problem? Many Thanks :rolleyes: Bravo Two Zero A pen is mighter then a sword.
-
Hello All, I have a validation, replacing quotation mark in my dll as soon as surname or first name has been passed from my form. The code is : CStr(Replace(Trim(surname), " ' ", "$0")) The problem is when I type a surname = "O'Brian" the data does not go to the database and has internal server error. Can anybody suggest any other way I can liminate this problem? Many Thanks :rolleyes: Bravo Two Zero A pen is mighter then a sword.
To place a single quotation mark into database, just repeat it, e.g. to use "
O'Brian
" in your SQL statement, you should replace it with "O''Brian
". You do not need to do that though if you are using ADO'sRecordest("field") = "O'Brian"
Philip Patrick Web-site: www.stpworks.com "Two beer or not two beer?" Shakesbeer -
Hello All, I have a validation, replacing quotation mark in my dll as soon as surname or first name has been passed from my form. The code is : CStr(Replace(Trim(surname), " ' ", "$0")) The problem is when I type a surname = "O'Brian" the data does not go to the database and has internal server error. Can anybody suggest any other way I can liminate this problem? Many Thanks :rolleyes: Bravo Two Zero A pen is mighter then a sword.
It looks like you probably used the variable surname as part of a SQL statement. With SQL, the value has to be quoted by ' such as:
select * from myTable where name = 'John Smith'
If the name value itself contains a ', the SQL statement is invalid:select * from myTable where name = 'John's Smith'
What you need to do is replace ' with two consecutive ', like the following:select * from myTable where name = 'John''s Smith' CStr(Replace(Trim(surname), "'", "''"))
Good luck.