查询Excel 2010中,当诊断的OLEDB例外
-
13-09-2019 - |
题
要查询经由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提供商未注册在该机器上 异常。
我怎样才能找到正确的连接字符串/供应商?
解决方案
也许你卸载Jet数据库引擎(ACE)组件?他们仍然可以从MSDN下载的的 2007 Office系统驱动程序:数据连接组件
其他提示
相信为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中生成的查询字符串,它有它的额外的条目。
我下载并安装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();
}
不隶属于 StackOverflow