简体   繁体   English

无法创建文件-Excel到数据集

[英]Failed to create file - excel to dataset

I am using an a .xlsx file and wanted to import the details to a dataset. 我正在使用.xlsx文件,并想将详细信息导入数据集。 but it gives an error "failure creating file" on the code MyCommand.Fill(DtSet); 但是它在代码MyCommand.Fill(DtSet);上给出错误“创建文件失败”;

please see the full code below 请参阅下面的完整代码

 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);

textBox1 is likely to be your TextBox control. textBox1可能是您的TextBox控件。 To use it's value, you should use the .Text property 若要使用它的值,应使用.Text属性

so, instead of Data Source=" + textBox1 + ";Extended Properties 因此,而不是Data Source=" + textBox1 + ";Extended Properties

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM