我遇到了这个异常:“Microsoft.ACE.OLEDB.12.0”提供程序未在本地计算机上注册。
我试图用 OleDBConnection 连接 Excel 2010 文件。我有 Windows 7 64 位和 Office 2010 32 位。
我尝试安装 Microsoft Access Database Engine 2010 Redistributable,建议来自: The 'Microsoft.ACE.OLEDB.12.0' provider is not registered in the local machine
我也试过这个建议: http ://social.msdn.microsoft.com/Forums/en-US/vstsdb/thread/1d5c04c7-157f-4955-a14b-41d912d50a64
它们都不适合我。有人帮忙吗?
这是我的代码: string connectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=d:\Sample.xlsx;Mode=Share Deny Write;Extended Properties=\"HDR=YES;\";Jet OLEDB:发动机类型=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);
ds.Tables[0].Rows.Count.Dump();
}
catch (Exception)
{
throw;
}
finally
{
connection.Close();
}