zoukankan      html  css  js  c++  java
  • asp.net采用OLEDB方式导入Excel数据时提示:未在本地计算机上注册"Microsoft.Jet.OLEDB.4.0" 提供程序"

     笔者在项目中做做了一个从Excel表格中导入数据的模块、大体上asp.net项目中导入Excel大体分成三类:

    1)采用c#内置方案System.Data.OleDb(限制较小, 通用)

    2)采用Excel的COM组件(会有版本问题)

    3)采用伪Excel文件、即使用文本流的方式根据需求自己定义数据格式。同时在服务端进行反格式化

    笔者采用的是方案一、相关联开发环境如下:

    Windows 7(x64)

    Visual Studio 2010

    方案中使用的代码:

    复制代码
    public sealed class ExcelHelper
    { private const string CONNECTION_STRING = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};Extended Properties=Excel 8.0;"; public static DataSet ExcelDataSource(string filePath, string sheetName) { OleDbDataAdapter oada = new OleDbDataAdapter("select * from [" + sheetName + "$]", string.Format(CONNECTION_STRING,filePath)); DataSet ds = new DataSet(); oada.Fill(ds); return ds; } public static List<string> ExcelSheetName(string filePath) { List<string> list = new List<string>(); OleDbConnection conn = new OleDbConnection(string.Format(CONNECTION_STRING, filePath)); conn.Open(); DataTable sheetNames = conn.GetOleDbSchemaTable (System.Data.OleDb.OleDbSchemaGuid.Tables, new object[] { null, null, null, "TABLE" }); conn.Close(); foreach (DataRow dr in sheetNames.Rows) { list.Add((string)dr[2]); } return list; }
    复制代码

    程序在执行时会抛出:

    异常详细信息: System.InvalidOperationException: 未在本地计算机上注册“Microsoft.Jet.OLEDB.4.0”提供程序。

    分析原因:

    用于 Access 和 Excel 数据库的 Microsoft OLE DB Provider for Jet 在 64 位版本中不可用。

    最终解决办法:

    在IIS中启用32位应该程序、设置见图。

  • 相关阅读:
    cygwin 下配置ssh
    使用MarsEdit写博客
    bash no job control in this shell
    安装devtoolset-2:因由安装gcc 4.8而引起
    AFNetworking Property with 'retain (or strong)' attribute must be of object type
    从xib 创建 collectionViewCell
    CocoaPods 安装
    个人理解的 Https 通信流程
    cellforrowatindexpath 不执行 的原因
    do{} while(0) 的意义和用法
  • 原文地址:https://www.cnblogs.com/51net/p/3917419.html
Copyright © 2011-2022 走看看