zoukankan      html  css  js  c++  java
  • 不能删除电子数据表的单元格

    使用OleDB方式操作Excel,删除Excel中的表时提示该错误。非常是奇怪(只是也是见怪不怪了,微软的东西就喜欢给出一些莫名其妙的错误提示),昨天还能删除的,今天就删除不了了(只是昨天到今天确实有个大动作。把系统Ghost到了SSD固态硬盘上了,但操作的Excel文件路径并没有改变)。

    具体错误信息:
    {System.Data.OleDb.OleDbException (0x80004005): 不能删除电子数据表的单元格。


    在 System.Data.OleDb.OleDbCommand.ExecuteCommandTextErrorHandling(OleDbHResult hr)
    在 System.Data.OleDb.OleDbCommand.ExecuteCommandTextForSingleResult(tagDBPARAMS dbParams, Object& executeResult)
    在 System.Data.OleDb.OleDbCommand.ExecuteCommandText(Object& executeResult)
    在 System.Data.OleDb.OleDbCommand.ExecuteCommand(CommandBehavior behavior, Object& executeResult)
    在 System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior behavior, String method)
    在 System.Data.OleDb.OleDbCommand.ExecuteNonQuery()
    在 Roadmap_Excel.Form1.button2_Click(Object sender, EventArgs e)

    相关代码:

    连接字符串:

    //定义OleDB连接字符串
                string strConn = "Provider=Microsoft.Ace.OleDb.12.0;Persist Security Info=False;" + "data source=" + @excelPath + ";Extended Properties='Excel 12.0; HDR=yes; IMEX=10'";
                OleDbConnection conn = new OleDbConnection();
                conn.ConnectionString = strConn;

    运行删除的代码:

                            try
                            {
                                cmd = new OleDbCommand("Drop Table [" + roadmapTableName + "]", conn);
                                cmd.ExecuteNonQuery();
                            }
                            catch (System.Exception ex)
                            {
                                textBox1.Text += ("删除数据表失败:" + ex.Message);
                                textBox1.Text += ("
    ");
                                //该 ISAM 不支持在链接表中删除数据。
                                cmd = new OleDbCommand("Delete From [" + roadmapTableName + "]", conn);
                                cmd.ExecuteNonQuery();
                            }

    实在找不到原因,那就手动删除吧。


    眼下还没找到解决的方法,网上也没搜索到相关问题的网页。

  • 相关阅读:
    TensorFlow学习('utf-8' codec can't decode byte 0xff in position 0: invalid start byte)
    Python常用库之三:Matplotlib
    线性回归 Python实现
    go 算法 查询字符在字符串中的位置
    Python与Go快速排序
    Python与Go斐波那契数列
    Python与Go选择排序
    Python与Go插入排序
    Python与Go冒泡排序
    git clone直接提交用户名和密码
  • 原文地址:https://www.cnblogs.com/gcczhongduan/p/5259515.html
Copyright © 2011-2022 走看看