Results 1 to 3 of 3
  1. #1
    Join Date
    Sep 2005
    Posts
    74

    Unanswered: Insert String with Single Quote(')

    Hi guys! Is it posible to insert a value with single quote(') in ms excel? My current code is displayed below. But when I try to insert a string say, "This message contains single quote(')" an error will occur stating
    Missing semicolon ( at end of SQL statement.
    Thanks in advance!


    Code:

    OleDbConnection conn = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0 ;Data Source=myDB.xls";Extended Properties=\"Excel 8.0;HDR=YES\"");
    OleDbCommand command = new OleDbCommand();
    command.Connection = conn;
    command.CommandText = "INSERT INTO myTable values('This message contains single quote(')');
    conn.Open();
    command.ExecuteNonQuery();

  2. #2
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    You want to escape the single quote.
    The way to do this is to double it up

    Code:
    Replace(input_string, "'", "''")
    George
    Home | Blog

  3. #3
    Join Date
    Sep 2005
    Posts
    74
    Thanks it work!!

Posting Permissions

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