3

我在 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

但是在运行我的代码时,我仍然会遇到相同的异常消息。我得到的例外是“'Microsoft.ACE.OLEDB.12.0'提供程序未在本地计算机上注册”

PLz帮我解决这个问题。

提前致谢。

4

2 回答 2

3

您可能在 64 位 Windows 上并安装了 32 位驱动程序。切换到 32 位编译或获取 64 位驱动程序。

于 2011-05-23T11:53:02.577 回答
1

你应该试试这个(确保你在 x86(32 位)机器上):

此下载将安装一组组件,可用于促进 2007 Microsoft Office System 文件和非 Microsoft Office 应用程序之间的数据传输。

http://www.microsoft.com/downloads/en/details.aspx?FamilyID=7554F536-8C28-4598-9B72-EF94E038C891&displaylang=en

于 2011-05-23T12:36:01.303 回答