可能性の重複:(コード作品OLEDBエクセル単一引用符エラー
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();
をしかし、私の問題は、単一引用符です:
OLEDB, Writing Excel cell without leading apostrophe
私はこのコードを使用しています下記画像参照)
修正方法?
example of problem http://www.freeimagehosting.net/newuploads/e32f9.jpg
これは文字列型を強制する "設計上の"動作です。私はあなたがそれを避けることはできないと思います。純粋なテキストの代わりに '.csv'ファイルを作成するのはどうですか? –