简体   繁体   English

c#-如何在Excel文件名包含空格的情况下指定连接字符串?

[英]how to specify the connection string if the excel file name contains white space?using c#

string connString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\\data\\[Proj_Resource Details 20110118.xlsx];Extended Properties=Excel 12.0";

i mentioned [ ] still it is throwing exception.how can i solve this problem. 我提到[]仍然会引发异常。如何解决此问题。 plz mention the correct path 请提正确的路径

将整个文件名用引号引起来,但是因为这是一个文字字符串,请使用\\“将其转义:

string connString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=\"D:\\data\\Proj_Resource Details 20110118.xlsx\";Extended Properties=Excel 12.0";

Have you tried it as just 你有没有尝试过

string connString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\\data\\Proj_Resource Details 20110118.xlsx;Extended Properties=Excel 12.0";

without the []s? 没有 []?

By the way, if you are not escaping anything, just use @ 顺便说一句,如果您没有转义任何东西,只需使用@

string connString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\data\Proj_Resource Details 20110118.xlsx;Extended Properties=Excel 12.0";

字符串connString = @“ Provider = Microsoft.ACE.OLEDB.12.0; Data Source = ”“ D:\\ data \\ Proj_Resource Details 20110118.xlsx \\”; **扩展属性= Excel 12.0“;

If you still cannot connect or get "Microsoft.ACE.OLEDB.12.0 provider is not registered on the local machine" error, you need to download the Microsoft Access Database Engine. 如果仍然无法连接或出现“未在本地计算机上注册Microsoft.ACE.OLEDB.12.0提供程序”错误,则需要下载Microsoft Access数据库引擎。

http://www.microsoft.com/en-us/download/details.aspx?id=13255 http://www.microsoft.com/zh-cn/download/details.aspx?id=13255

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何通过连接字符串在c#中读取Excel文件? - How to read Excel file in c# by connection string? 如果字符串在c#中有空或空格,如何返回false - how to return false if string has null or white space in c# 如何在 C# / VSTO 中为 Excel 数据 Model 连接指定使用 XlCmdType.xlCmdTableCollection 的表 - How do I specify the tables using XlCmdType.xlCmdTableCollection for an Excel Data Model connection in C# / VSTO 如何使用C#在Excel中更改ODC连接文件路径 - How to change the odc connection file paths in excel using c# 使用C#和ADO OLEDB连接字符串创建一个Excel文件。 如何在Excel粗体显示标题行? - Using C# and ADO OLEDB connection string to create an excel file. How do i make the header row in excel bold? 根据 C# 中的空格拆分字符串 - Split a string based on white space in C# 用于空白的C#字符串存储 - C# string storage for white-space 如何使用C#修剪正则表达式中的空白 - How to trim white space within Regex using c# 如何使用 LDAP 为 ORACLE 设置 C# 连接字符串以指定数据库? - How can I setup a C# connection string for ORACLE using LDAP to specify the database? c# WPF 如何调用或调用按钮 function 使用字符串变量,字符串变量包含按钮名称? - c# WPF How to invoke or call button function using string variable, the string variable contains the button name?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM