Custom embed the data source variable in the connection string

Custom embed the data source variable in the connection string

how do I custom call the data source of a connection string, the existing connection string is stored in the web.config file. I am using Oledb to connect to an Excel sheet uploaded to the server.

how do I custom call the data source of a connection string, the existing connection string is stored in the web.config file. I am using Oledb to connect to an Excel sheet uploaded to the server.

I have got my connection strings in the web.config file. Earlier, I was hard-coding the entire string including the data source location in the web.config file.

//this one works
<add name="testexcel1" connectionString="Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\usethis\WebApplication1\Uploaded Files\weekly output target.xlsx;Extended Properties='Excel 12.0 Xml;HDR=No;IMEX=1;MAXSCANROWS=0'"/>

//I would like to specify the data source parameter in my code behind file. <add name="testexcel" connectionString="Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};Extended Properties='Excel 8.0;HDR=No'"/>

//this is what I am trying to do, but it just does not work, the string gets concatenated wrongly. string fileLocation = Server.MapPath("~/Uploaded Files/" + filename); builder.Provider = ConfigurationManager.ConnectionStrings["testexcel1"].ConnectionString; builder.DataSource = accept_filelocation;

//This is finally working string connectionStringProvider = ConfigurationManager.ConnectionStrings["testexcel1"].ConnectionString;

    string dataSource = accept_filelocation;

    string connectionString = String.Format(connectionStringProvider, dataSource);



    OleDbConnection oledbConn = new OleDbConnection(connectionString);


Angular 9 Tutorial: Learn to Build a CRUD Angular App Quickly

What's new in Bootstrap 5 and when Bootstrap 5 release date?

Brave, Chrome, Firefox, Opera or Edge: Which is Better and Faster?

How to Build Progressive Web Apps (PWA) using Angular 9

What is new features in Javascript ES2020 ECMAScript 2020

Add asp.net Identity in empty project

LIKE | COMMENT | SHARE | SUBSCRIBE Today, in this tutorial you will see the process of adding an ASP.NET Identity to the ASP.NET Web Application developed in...

List all users from asp net core identity

LIKE | COMMENT | SHARE | SUBSCRIBE In this video, i will show you How to retrieve and display all the registered application users in asp.net core using the ...

Extend IdentityUser in ASP NET Core

LIKE | COMMENT | SHARE | SUBSCRIBE In this tutorials, I will show you how to extend IdentityUser in asp.net core.. Subscribe & Stay Connected! Thank You! ♥ #...