locked
Cannot update string with " ' " character in a database. RRS feed

  • Question

  • Hi
    I used to take a string from a text box in vb.net and pass it to a sql query to update or insert in a database.
    I faced a problem when the set of characters in the text box contain " ' " (single quote), it throws a error "unclosed quotation mark".
    Can anybody help me ?
    • Moved by OmegaMan Friday, May 29, 2009 10:42 PM (From:Regular Expressions)
    Friday, May 29, 2009 10:48 AM

Answers

  • You need to use the parameter classes rather then trying to hardcode the value directly into the SQL string.
    John Grove - TFD Group, Senior Software Engineer, EI Division, http://www.tfdg.com
    Friday, May 29, 2009 4:55 PM

All replies

  • Hi,

    I don't think the problem is related to regular expressions.

    Your problem seams to be an escape sequence for your character: try using two single quote instead of just one to escape the quote.

    Hope it hleps.
    Grégory Schiro - PowerShell & MOF
    • Proposed as answer by Grégory Schiro Friday, May 29, 2009 12:07 PM
    • Unproposed as answer by CSHEKHAR U Friday, May 29, 2009 2:58 PM
    Friday, May 29, 2009 12:07 PM
  • You need to use the parameter classes rather then trying to hardcode the value directly into the SQL string.
    John Grove - TFD Group, Senior Software Engineer, EI Division, http://www.tfdg.com
    Friday, May 29, 2009 4:55 PM
  • Can you display your code so we can help you resolve this?
    John Grove - TFD Group, Senior Software Engineer, EI Division, http://www.tfdg.com
    Friday, May 29, 2009 10:46 PM