Csharp/C#教程:ConnectionString用于获取Excel文件问题分享


ConnectionString用于获取Excel文件问题

在名为(ExcelFiles)的文件夹中有一个Excel文件命名(a.xlsx)。

ExcelFiles文件夹位于我的项目的根目录中。

所以我获取excel文件数据的连接字符串是这样的:

 

aaa =我的项目名称

使用此连接字符串,每个东西在本地都可以,但上传网站后我有一个错误。

问题出在哪儿??

这条路是真的 – >〜/ ExcelFiles / a.xlsx与否

你能解决这条道路吗我…

解决路径问题后,错误是这样的:

  The 'Microsoft.ACE.OLEDB.12.0' provider is not registered on the local machine. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.InvalidOperationException: The 'Microsoft.ACE.OLEDB.12.0' provider is not registered on the local machine. 

我怎么能处理这个错误?

谢谢你的未来发展

最好的祝福

您托管文件的计算机没有安装ACE OleDB for office驱动程序。 我会切换到JetOleDB驱动程序

Jet OleDB连接字符串看起来像

 Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};Extended Properties="Excel 8.0;HDR=Yes;IMEX=1"; 

我相信Excel8.0是2003版。 对于2007年,您将需要使用Excel12.0

所以我要做的就是做一个String.Format并简单地传入excel文件的位置,当然因为这看起来像是一个asp.net应用程序所以它应该是这样的:

 String con = String.Format( @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};Extended Properties="Excel 8.0;HDR=Yes;IMEX=1"", Server.MapPath(EXCEL FILE LOCATION) ); 

您当然可以简单地将String.Format中使用的String放在配置文件中,这样就不像我拥有的​​那样硬编码。

看看下面的url,它有关于如何解决此问题的信息

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

上述就是C#学习教程:ConnectionString用于获取Excel文件问题分享的全部内容,如果对大家有所用处且需要了解更多关于C#学习教程,希望大家多多关注—计算机技术网(www.ctvol.com)!

本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。

ctvol管理联系方式QQ:251552304

本文章地址:https://www.ctvol.com/cdevelopment/960059.html

(0)
上一篇 2021年11月24日
下一篇 2021年11月24日

精彩推荐