Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/315.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Oledb无法访问文件修复程序_C#_.net_Excel_Oledb - Fatal编程技术网

C# Oledb无法访问文件修复程序

C# Oledb无法访问文件修复程序,c#,.net,excel,oledb,C#,.net,Excel,Oledb,对于一个小项目,我需要创建一个数据表,其中包含来自Excel工作表的数据。我使用Oledb连接获取此数据。有时其他人正在服务器上使用此文件。所以我得到了“进程无法访问该文件,因为它正被另一个进程使用” 有没有办法用Oledb来完成这个任务?问题是什么?你有什么错误吗?哪些错误?你是说代码在服务器上不起作用吗?服务器是否有Jet OLEDB提供程序?@PanagiotisKanavos Im收到“该进程无法访问该文件,因为它被另一个进程使用”错误。 private DataTable excelS

对于一个小项目,我需要创建一个数据表,其中包含来自Excel工作表的数据。我使用Oledb连接获取此数据。有时其他人正在服务器上使用此文件。所以我得到了“进程无法访问该文件,因为它正被另一个进程使用”


有没有办法用Oledb来完成这个任务?

问题是什么?你有什么错误吗?哪些错误?你是说代码在服务器上不起作用吗?服务器是否有Jet OLEDB提供程序?@PanagiotisKanavos Im收到“该进程无法访问该文件,因为它被另一个进程使用”错误。
private DataTable excelSelectStatement() {
        try {
            string par = this._colParameters.getParameterByName("SheetName", false, null).Value;
            excelDataSet = new DataSet();
            string ace12 = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source='" + _selectionStatement + "';Extended Properties='Excel 12.0;HDR=YES;IMEX=1;';";
            using (OleDbConnection connection = new OleDbConnection(ace12)) {
                OleDbDataAdapter da = new OleDbDataAdapter("select * from [" + par + "$]", connection);
                da.TableMappings.Add("Table", "TestTable");
                da.Fill(excelDataSet);
            }
        }
        catch (Exception e) { MessageBox.Show(e.Message); }
        return excelDataSet.Tables[0];
    }