【发布时间】:2017-02-27 10:02:25
【问题描述】:
我想在 oledb 的无标题 excel 表中插入一些行。例如,通过以下查询插入 A、B、C 和 E 列:
Insert into [Sheet1$] (A,B,C,E) values('0','a','zz''2019-09-09')";
但是,我收到了一个错误,即未找到 A 列。
谁能告诉我如何在无标题的 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.ACE.OLEDB.12.0;Data Source='C:\excelFile.xlsx';Extended Properties=Excel 12.0;");
myCommand.Connection = MyConnection;
sql = "Insert into [Sheet1$] (A,B) values('0','a')";
myCommand.CommandText = sql;
myCommand.ExecuteNonQuery();
MyConnection.Close();
【问题讨论】: