问题描述
我在Win 7机器上使用VS2010在.NET 4.0框架上运行ASP.NET C#应用程序。在我的代码中,我想将Excel文件与\“ DataTable \”对象链接。即我想访问Excel文件中的数据并将其存储在DataTable对象中。因此,我使用了以下代码片段:
_
_connectionString = \"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=\\\"\" + excelFile + \"\\\";Extended Properties=\'Excel 8.0; HDR=NO; IMEX=1\'\";
}
DataTable table = new DataTable();
OleDbCommand command = new OleDbCommand();
command.Connection = new OleDbConnection(_connectionString);
command.CommandType = CommandType.Text;
command.CommandText = \"select * from [NameOFExcelSheet$A1:D20]\"; // Want to read the Excel sheet. The name of Excel sheet is \"NameOfExcelSheet\". Wan to read the celles in the range A1 and D20.
OleDbDataAdapter adapter = new OleDbDataAdapter();
adapter.SelectCommand = command;
adapter.Fill(table); // EXCEPTION OCCURS IN THIS LINE.
我安装了可通过链接http://www.microsoft.com/downloads/en/confirmation.aspx?FamilyID=7554F536-8C28-4598-9B72-EF94E038C891&displaylang=en获得的exe。
但是我在运行代码时仍然遇到相同的异常味精。
我得到的例外是\“ \'MicrosoftMicrosoft.ACE.OLEDB.12.0 \”提供程序未在本地计算机上注册\“
PLz帮我解决这个问题。
提前致谢。
解决方法
您可能在64位Windows上,并安装了32位驱动程序。切换到32位编译或获取64位驱动程序。
,您应该尝试这样做(确保您位于x86(32位)计算机上):
此下载将安装一组组件,这些组件可用于促进2007 Microsoft Office System文件与非Microsoft Office应用程序之间的数据传输。
http://www.microsoft.com/downloads/zh-CN/details.aspx?FamilyID=7554F536-8C28-4598-9B72-EF94E038C891&displaylang=en