开发者

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_开发者_JAVA百科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


Wrap the whole filename in quotes, but because this is a literal string use \" to escape them:

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";


string connString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=\"**D:\data\Proj_Resource Details 20110118.xlsx\";**Extended Properties=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.

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜