![](/img/trans.png)
[英]System.Data.OleDb.OleDbException: 'Syntax error in UPDATE statement. '
[英]Syntax error in INSERT INTO statement./Excel/oledb
我正在嘗試使用OledbDataAdapter更新MS-Excel文件,並且收到“插入到語句中的語法錯誤”
這是我的代碼:
private void btnLoadPremiumDetail_Click(object sender, RoutedEventArgs e) {
OpenFileDialog openFileDialog = new OpenFileDialog();
string fileName = "";
if (openFileDialog.ShowDialog() == true)
fileName = openFileDialog.FileName;
else
return;
string sConnection = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + fileName + ";Extended Properties='Excel 12.0;HDR=No;IMEX=1'";
this.connection = new OleDbConnection(sConnection);
this.connection.Open();
var dtTablesList = connection.GetSchema("Tables");
var sSheetName = "";
if (dtTablesList.Rows.Count > 0)
sSheetName = dtTablesList.Rows[0]["TABLE_NAME"].ToString();
dtTablesList.Clear();
dtTablesList.Dispose();
if (!string.IsNullOrEmpty(sSheetName)) {
var command = new OleDbCommand("Select * From [" + sSheetName + "]", connection);
this.adapter = new OleDbDataAdapter(command);
new OleDbCommandBuilder(this.adapter);
this.table = new DataTable();
this.adapter.Fill(table);
this.dgExcelData.ItemsSource = table.DefaultView;
}
}
private void btnSave_Click(object sender, RoutedEventArgs e) {
this.adapter.Update(this.table);
this.lblStatus.Content = "Data saved";
}
我決定嘗試使用ClosedXML: http : //closedxml.codeplex.com/
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.