Results 1 to 4 of 4

Thread: The Apostrophy Problem?

  1. #1

    Thread Starter
    Frenzied Member HarryW's Avatar
    Join Date
    Jan 2000
    Location
    Heiho no michi
    Posts
    1,827

    Post

    Yes, because, in a similar way to Pascal, two single quotes in a row is interpreted as one single quote contained within a string.

    I just thought maybe that could do with explaining.

  2. #2
    Lively Member Nator's Avatar
    Join Date
    Nov 1999
    Location
    East Larryville, GA
    Posts
    80

    Post

    That worked. Thanks for the help.

  3. #3
    Lively Member Nator's Avatar
    Join Date
    Nov 1999
    Location
    East Larryville, GA
    Posts
    80

    Post

    Does anyone have a work around for handling strings containing apostrophies that are being passed into a SQL statement?
    Example. I have form with a textbox for Last Name, First Name and Phone Number. If the lastname box contains something like O'Hara I get a syntax error when I try to run
    "INSERT INTO contacts (lastname, firstname, phone) VALUES ('" & txtLastname.text & "', '" & txtFirstname.text & "', '" & txtPhone.text & "'). The apostrophy in O'Hara is being confused with the tick in my SQL statement. I am using an Access database.
    Any help would be appreciated.

  4. #4
    Guru Clunietp's Avatar
    Join Date
    Oct 1999
    Location
    USA
    Posts
    1,844

    Post

    you can use the VB6 REPLACE function to find those single quotes and convert them to double single quotes...

    Code:
    dim strSQL as string
    
    strSQL = "Select * from Customers where CustomerID = '" & replace(text1.text, "'", "''") & "'"
    HTH

    Tom

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