2009-09-22 33 views
2

要查詢通過SQL Excel工作表,我用兩種:直到我安裝了Office 2010診斷的OLEDB異常時Quering Excel 2010中

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

現在這個工作得很好。

現在,我得到一個

MICR osoft.Ace.OLEDB.12.0提供商未在本機上註冊 異常。

我怎樣才能找到正確的連接字符串/供應商?

回答

7

我相信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中生成的查詢字符串,它有它的額外名額。

+0

已經試過了,也不行... – 2009-09-22 16:28:25

+0

更新它 - 它沒有工作的無論礦,新一不 – JDunkerley 2009-09-22 20:02:49

+0

我今天就遇到了這個相同的情況和你的回答是非常有益的 – 2012-09-18 12:11:15

2

我下載並安裝Office系統驅動程序:數據連接組件如上建議 - 與下面的代碼工作:

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(); 
    } 
+0

我怎麼沒有得到任何結果。儘管如此,它並沒有給我帶來任何異常。 – Meidi 2012-11-01 21:21:22