【问题标题】:Failed to create file - excel to dataset无法创建文件 - excel 到数据集
【发布时间】:2017-07-03 08:03:46
【问题描述】:

我正在使用 .xlsx 文件并希望将详细信息导入数据集。 但它在代码 MyCommand.Fill(DtSet) 上给出错误“创建文件失败”;

请看下面的完整代码

 System.Data.OleDb.OleDbConnection MyConnection;
            System.Data.DataSet DtSet;
            System.Data.OleDb.OleDbDataAdapter MyCommand;
            MyConnection = new System.Data.OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + textBox1 + ";Extended Properties=Excel 12.0;");
            MyCommand = new System.Data.OleDb.OleDbDataAdapter("select * from [Sheet1]", MyConnection);
            MyCommand.TableMappings.Add("Table", "TestTable");
            DtSet = new System.Data.DataSet();
            MyCommand.Fill(DtSet);

【问题讨论】:

  • 工作簿是否已经包含一个名为“TestTable”的工作表?

标签: c# database winforms oledb


【解决方案1】:

textBox1 可能是您的 TextBox 控件。要使用它的值,您应该使用.Text 属性

所以,而不是 Data Source=" + textBox1 + ";Extended Properties

使用 Data Source=" + textBox1.Text + ";Extended Properties

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-08-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多