Results 1 to 4 of 4

Thread: [RESOLVED] SQL INSERT with apostrophes

Hybrid View

  1. #1

    Thread Starter
    Member
    Join Date
    Nov 2005
    Posts
    37

    Resolved [RESOLVED] SQL INSERT with apostrophes

    I am coding in Visual Basic .NET, and using Visual Studio .NET 2003. I am working with SQL Server 2005 Express.

    I'm trying to insert strings among other things into a database I have created. The problem is when I try to insert a string with an apostrophe in it (i.e. "Let's go") I'm having issues because the SQL command ends up looking something like this:

    INSERT INTO table1('Let's go')

    As you can see the apostrophe messes up my quotes, I've tried using double quotes but they won't work :/

    I was looking into converting the string into unicode or something similar, but is there an easier way around this?
    Last edited by JSand4325; Apr 20th, 2006 at 12:18 AM.

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: [02/03] SQL INSERT with apostrophes

    Don't use double-quotes, use two single-quotes.

    Code:
    INSERT INTO table1('Let''s go')
    (I'm afraid I dont know the .Net code to add the extra single quote)

  3. #3
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: [02/03] SQL INSERT with apostrophes

    stringname.replace("'","''")

    Or just use parameterized queries/stored procs.

  4. #4

    Thread Starter
    Member
    Join Date
    Nov 2005
    Posts
    37

    Re: [02/03] SQL INSERT with apostrophes

    thanks I used the replace method for now. I don't know if parameterized queries could apply to what I'm doing, but I'll do more research on them when I'm going over this with a fine tooth comb.

    Thanks again!

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