Results 1 to 5 of 5

Thread: Apostrophe Error

  1. #1

    Thread Starter
    Addicted Member smh's Avatar
    Join Date
    Oct 2000
    Location
    South Dakota, USA
    Posts
    249

    Apostrophe Error

    I am using the following code to submit values to a database. How can I adjust the code to allow information with apostophes to be allowed without messing up the SQL statement? (Using VBScript)

    function UpdateNearestRelative()

    appid = session("appID")
    sqlUpdateApplicant = "Update ApplicantInfo set"
    sqlUpdateApplicant = sqlUpdateApplicant & " NearRelative = '" & Request.Form("txtNRName") & "', "
    sqlUpdateApplicant = sqlUpdateApplicant & " R_Address = '" & Request.Form("txtNRAddress") & "', "
    sqlUpdateApplicant = sqlUpdateApplicant & " R_City = '" & Request.Form("txtNRCity") & "', "
    sqlUpdateApplicant = sqlUpdateApplicant & " R_State = '" & Request.Form("txtNRState") & "', "
    sqlUpdateApplicant = sqlUpdateApplicant & " R_Zip = '" & Request.Form("txtNRZip") & "', "
    sqlUpdateApplicant = sqlUpdateApplicant & " R_Phone = '" & Request.Form("txtNRPHAreaCode") & Request.Form("txtNRPHPrefix") & Request.Form("txtNRPhNum") & "' "

    sqlUpdateApplicant = sqlUpdateApplicant & " where ApplID = " & appid



    Conn.Execute(sqlUpdateApplicant)

    end function



    Thanks!
    Normal is boring...

    smh

  2. #2
    Addicted Member
    Join Date
    Aug 2000
    Location
    Pennsylvania, USA
    Posts
    168
    Use the replace function to replace one single quote with two single quotes for each string value going into your insert statement

    Code:
    strSomeStrimg = Replace(strSomeStrimg, "'", "''")
    Wydok

    "It would appear that we have reached the limits of what it is possible to achieve with computer technology, although one should be careful with such statements, as they tend to sound pretty silly in 5 years."

    -John Von Neumann ca. 1949

  3. #3
    Frenzied Member
    Join Date
    Feb 2001
    Posts
    1,140
    Code:
    strSQL = strSQL & Replace(strSomeValue, "'", "''")
    You have to escape apostrophe's in SQL with another apostrophe. There is a thread about posting O'Something names.

    Edit: Sorry, I got bored and kind of felt my code sample might be misleading, so I edited it.
    Last edited by CiberTHuG; Dec 19th, 2001 at 12:29 PM.
    Travis, Kung Foo Journeyman
    As always, RTFM.

    WWW Standards: HTML 4.01, CSS Level 2, ECMA 262 Bindings to DOM Level 1, JavaScript 1.3 Guide and Reference
    Perl: Learn Perl, Llama, Camel, Cookbook, Perl Monks, Perl Mongers, O'Reilly's Perl.com, ActiveState, CPAN, TPJ, and use Perl;
    YBMS, but Mozilla doesn't.

  4. #4
    Frenzied Member
    Join Date
    Feb 2001
    Posts
    1,140
    Yeah, as Wydok said.
    Travis, Kung Foo Journeyman
    As always, RTFM.

    WWW Standards: HTML 4.01, CSS Level 2, ECMA 262 Bindings to DOM Level 1, JavaScript 1.3 Guide and Reference
    Perl: Learn Perl, Llama, Camel, Cookbook, Perl Monks, Perl Mongers, O'Reilly's Perl.com, ActiveState, CPAN, TPJ, and use Perl;
    YBMS, but Mozilla doesn't.

  5. #5

    Thread Starter
    Addicted Member smh's Avatar
    Join Date
    Oct 2000
    Location
    South Dakota, USA
    Posts
    249
    Thanks!
    Normal is boring...

    smh

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width