About the apostrophes in sql

Discussion in 'Programming' started by Ngajel, Aug 23, 2010.

  1. #1
    I am desinging the small program to insert the text from user side. When the user type the data like word don't which it contains apostrophes, its throwing some error in sql 2003. As a front-hand m using vb 6 and back-hand sql2003. I made datatype as varchar.

    Please help me
     
    Ngajel, Aug 23, 2010 IP
  2. Rainulf

    Rainulf Active Member

    Messages:
    373
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    85
    #2
    You need to escape (eg. don\'t) all apostrophes to prevent this error. In PHP, there's a function that does this already, I'm not sure with vb. In addition, you should filter all the user input because a user can run an unwanted query - such as deleting everything in your database.
     
    Rainulf, Aug 24, 2010 IP
  3. sql

    sql Peon

    Messages:
    33
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    I think you may use double apostrophes '' instead of single apostrophes '
    Like:
    INSERT INTO TableName
    VALUES ('don''t')

    In vb6, you could use function Replace(txt,"'","''")
     
    sql, Aug 24, 2010 IP