What is the connection string to connect to Excel sheet with .xls and .xlsx extension in C#, ASP.Net?
Sometimes, we may get some data in excel sheet which needs to be uploaded into our application database. In this case, it will be easy if we connect to excel sheet like we connecting to a database and querying it using ADO.Net classes. To connect to excel sheet we need to first form the connection string to connect to a excel sheet and configure it in web.config file. This little FAQ will help you form the connection string to connect to microsoft excel sheet to connect it through ADO.Net.
The below connection string can be used to connect to a excel sheet with .xls extension copied to App_Data folder in your project solution.
<add name="ExcelOld" connectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|NewEmployees.xls;Extended Properties=Excel 8.0"/>
As we know, after Microsoft released a new extension .xslx for excel sheet. To connect to .xslx extension excel sheet copied to App_Data folder,
<add name="ExcelCon" connectionString="Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|NewEmployees.xlsx;Extended Properties=Excel 12.0"/>
Refer the below link to connect to excel sheet and to read it using ADO.Net.
How to connect to Excel Sheet(.xls) Using C# and ASP.Net?