c# - 参数异常 : Format of the initialization string does not confirm to specification starting at index 102

标签 c# database oledbconnection jet

我正在通过 winforms 中的 datagridview 将 excel 文件导入数据库。单击“导入 Excel 文件”按钮时出现此异常。在该行引发的异常:

OleDbConnection con = new OleDbConnection(connectionString);

我的连接字符串是:

string connectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=G:\GPS_WTGs.xlsx;Extended Properties=\"Excel 8.0;HDR=Yes;\";

在我的 winform 中,我只有 1 个按钮和 datagridview。

如何处理这个异常?

最佳答案

您的连接字符串格式不正确,您不需要额外的 " 和反斜杠。您可以尝试以下方法:

string connectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=G:\GPS_WTGs.xlsx;Extended Properties=Excel 8.0;HDR=Yes;"

关于c# - 参数异常 : Format of the initialization string does not confirm to specification starting at index 102,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45205661/

相关文章:

php - 我的虚拟主机主目录中的数据库连接

c# - 如何从 C# 连接到不同版本的 Excel?

sql-server - 使用 Microsoft OLE DB 提供程序和 SQL Native OLE DB 提供程序建立 DB 连接

c# - 防止属性被序列化

sql - 需要在 SQL 查询中替换 union

database - 如何在 Quest Toad "Browse Database Objects" View 中将字段设置为空?

excel - OleDbConnection 未能创建新的 excel 文件

c# - 将小数转换为尽可能小的数字类型,不会丢失任何数据

c# - ASP.Net MVC3 下拉列表和传递数据

c# - 由于未连接Socket而导致System.Net.SocketException