If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > PC based Database Applications > Microsoft Excel > Insert String with Single Quote(')

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 10-07-08, 03:23
daimous daimous is offline
Registered User
 
Join Date: Sep 2005
Posts: 72
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
Quote:
Missing semicolon ( at end of SQL statement.
Thanks in advance!


Code:
Quote:

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();
Reply With Quote
  #2 (permalink)  
Old 10-07-08, 03:32
gvee gvee is offline
www.gvee.co.uk
 
Join Date: Jan 2007
Location: UK
Posts: 10,156
You want to escape the single quote.
The way to do this is to double it up

Code:
Replace(input_string, "'", "''")
__________________
George
Twitter | Blog
Reply With Quote
  #3 (permalink)  
Old 10-07-08, 05:42
daimous daimous is offline
Registered User
 
Join Date: Sep 2005
Posts: 72
Thanks it work!!
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On