November 12, 2001 at 9:49 am
Here's an interesting problem.
I've got a form that feeds a table, and all goes well until the user enters a word that has an apostrophe co-joiningg words, (I'm / I've), at which point I get the error, as the input string gets terminated at that point.
Is there a good way of error trapping this?
The affected field is an nvarchar with 255 length.
November 12, 2001 at 9:57 am
Use the REPLACE function before the insert to replace all single quotes with double quotes. This "escapes" the single quote.
Steve Jones
November 12, 2001 at 10:11 am
Thanks (again) Steve.
November 12, 2001 at 10:29 am
November 12, 2001 at 12:07 pm
function SQLparse(s)
'*********************************************
'* This just does a charater replacement on my
'* insert and update sections
'* so I don't blow up the database.
'*********************************************
dim tmp
tmp = s
tmp = replace(tmp, "’", "'")
tmp = replace(tmp, "`", "'")
tmp = replace(tmp, "'", "''")
SQLparse = tmp
'SQLparse end
end function
Here is a little asp function I wrote to do that.
Wes
November 12, 2001 at 1:19 pm
Thanks Wes, we have a similar one at SSC, but we don't include the `. Does that one cause problems?
Steve Jones
November 13, 2001 at 2:15 am
I don't think me not posting is an option at the moment, but as soon as I contribute something other than questions, I will.
Any other suggestions for a replacement to '
that won't crash the coding?
November 15, 2001 at 4:42 am
Another thing you can do if you want to preserve the apostrophe is using the replace function in the same way that was described but this time replace the single quote with three single quotes (or is it 5 quotes).
This in effect wraps the quotes around the apostrophe and allows you to preserve the apostrophe.
Karl Grambow
Viewing 8 posts - 1 through 7 (of 7 total)
You must be logged in to reply to this topic. Login to reply