可能重複:
OLEDB, Writing Excel cell without leading apostropheOLEDB Excel中單引號錯誤
我使用這個代碼:
System.Data.OleDb.OleDbConnection MyConnection;
System.Data.OleDb.OleDbCommand myCommand = new System.Data.OleDb.OleDbCommand();
string sql = null;
MyConnection = new System.Data.OleDb.OleDbConnection("provider=Microsoft.Jet.OLEDB.4.0;Data Source='c:\\test_excel.xls';Extended Properties=Excel 8.0;");
MyConnection.Open();
myCommand.Connection = MyConnection;
sql = "CREATE TABLE EmployeeData (Id char(255), Name char(255), BirthDate date)";
myCommand.CommandText = sql;
myCommand.ExecuteNonQuery();
sql = "INSERT INTO EmployeeData (Id, Name, BirthDate) values ('AAA', 'Andrew', '12/4/1955')";
myCommand.CommandText = sql;
myCommand.ExecuteNonQuery();
MyConnection.Close();
代碼的作品,但我的問題是單引號(見下圖)
如何解決?
example of problem http://www.freeimagehosting.net/newuploads/e32f9.jpg
這是「通過設計」行爲強制字符串類型 - 我不認爲你可以避免它。怎麼樣創建純文本'.csv'文件呢? –