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

前端 未结 4 1670
北荒
北荒 2020-12-12 01:22
string connString = \"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\\\\data\\\\[Proj_Resource Details 20110118.xlsx];Extended Properties=Excel 12.0\";


        
相关标签:
4条回答
  • 2020-12-12 01:44

    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 讨论(0)
  • 2020-12-12 01:56

    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";
    
    0 讨论(0)
  • 2020-12-12 02:06

    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";
    
    0 讨论(0)
  • 2020-12-12 02:09

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

    0 讨论(0)
提交回复
热议问题