首页 文章

在Quering Excel 2010中诊断OLEDB异常

提问于
浏览
2

要通过SQL查询excel表,我曾经使用过:

Dim excelConnectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + strPath + ";Extended Properties=""Excel 8.0;IMEX=1;HDR=YES;"""

要么

Dim excelConnectionString As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source= " + strPath + ";Extended Properties=""Excel 12.0;IMEX=1;HDR=YES;"""

现在这个工作正常,直到我安装了Office 2010 .

现在我得到了

Microsoft.Ace.OLEDB.12.0提供程序未在此计算机上注册异常 .

如何找到正确的连接字符串/提供程序?

3 回答

  • 1

    也许您卸载了Access数据库引擎(ACE)组件?它们仍然可以从MSDN下载2007 Office System Driver: Data Connectivity Components .

  • 2

    我相信Excel 2010它是:

    Dim excelConnectionString As String = "Provider=Microsoft.ACE.OLEDB.12.0;Password="""";User ID=Admin;Data Source=D:\\MyDocs\\oledb.xlsx;Mode=Share Deny Write;Extended Properties=""HDR=YES;"";Jet OLEDB:Engine Type=37"
    

    这似乎在我的视觉工作室中工作,我得到Excel生成查询字符串,它有额外的条目 .

  • 7

    我按照上面的建议下载并安装了Office System Driver:Data Connectivity Components - 以下代码有效:

    string connectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Password=\"\";User ID=Admin;Data Source=d:\\Sample.xlsx;Mode=Share Deny Write;Extended Properties=\"HDR=YES;\";Jet OLEDB:Engine Type=37";
    
        OleDbConnection connection = new OleDbConnection(connectionString);
    
        try
        {
            connection.Open();
    
            OleDbCommand command = new OleDbCommand("SELECT * FROM [Sheet1$]", connection);
            OleDbDataAdapter adapter = new OleDbDataAdapter();
            adapter.SelectCommand = command;
    
            DataSet ds = new DataSet();
            adapter.Fill(ds);
    
            GridView1.DataSource = ds;
            GridView1.DataBind();
    
        }
        catch (Exception)
        {            
            //throw;
        }
        finally
        {
            connection.Close();
        }
    

相关问题