ASP forms & SQL syntax error

  • 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.

  • Use the REPLACE function before the insert to replace all single quotes with double quotes. This "escapes" the single quote.

    Steve Jones

    steve@dkranch.net

  • Thanks (again) Steve.

  • Glad we could help. Keep posting!!!!!

    Steve Jones

    steve@dkranch.net

  • 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

  • Thanks Wes, we have a similar one at SSC, but we don't include the `. Does that one cause problems?

    Steve Jones

    steve@dkranch.net

  • 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?

  • 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