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
精彩评论