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


c-sharp asp.net

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

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

What is new features in Javascript ES2020 ECMAScript 2020

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

Random Password Generator Online

HTML Color Picker online | HEX Color Picker | RGB Color Picker

Various ways of redirecting a request in Asp.Net Core

ASP.NET Core web applications often need to redirect a request to another resource based on some condition. There are multiple ways in which you can accomplish this task in ASP.NET Core MVC and Razor&#160;&#8230;

Routing in MVC - ASP.NET Core Demystified

ASP.NET Core MVC has introduced quite a few concepts that new (or new-to-ASP.NET) web developers might have some difficulty getting caught up with. My ASP.NET Core Demystified series is designed to help these developers get started building their own custom, full-fledged, working AASP.NET Core applications. In

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! ♥ #...