当前位置:Gxlcms > 数据库问题 > oledb 处理excel 报错 UPDATE “Operation must use an updateable query”

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

时间:2021-07-01 10:21:17 帮助过:44人阅读

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


连接逻辑如下:

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

更新语句如下

 string sql = "UPDATE [Sheet2$] 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的博文

本文出自 “不会飞的蚂蚁” 博客,请务必保留此出处http://cseck100150.blog.51cto.com/3499398/1792230

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

标签:c#   excel   imex   

人气教程排行