22312312 发表于 2016-6-24 08:56:43

oledb 处理excel 报错 UPDATE “Operation must use an updateable query”

使用C# OLEDB方式 更新excel中的数据时候,发现报错{"Operation must use an updateable query."}

连接逻辑如下:

1
connStr = "Provider=Microsoft.ACE.OLEDB.12.0;" + "Data Source=" + filePath + ";" + ";Extended Properties=\"Excel 12.0 XML;HDR=YES;IMEX=2\"";




更新语句如下

1
2
3
4
5
6
7
8
string sql = "UPDATE SET val = 66.259 WHERE tid =3;"
conn = new OleDbConnection(connStr);
conn.Open();
OleDbCommand cmd = new OleDbCommand();
cmd.Connection = conn;
cmd.CommandText = sql;
cmd.ExecuteNonQuery();
conn.Close();




报错为Operation must use an updateable query,期初以为是update语句执行失败,怎么修改都成功;
经过验证,问题出现在connStr 的 IMEX=2,取消此设置,OK,具体可参考popoxxll的博文

页: [1]
查看完整版本: oledb 处理excel 报错 UPDATE “Operation must use an updateable query”