开发者

How to give dynamic DataSource name in App.config

I am reading excel file and for that I do have connection string in App.config but I want to read each day the excel which is today's excel..

Each excel name is today's date(MM/dd/yy), so datasource name is somewhat dynamic. how to write the connection string in App.Config then

I want to use something like

<add name="Excels" connectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=..\..\[Today'sDate].xls;开发者_如何学运维Extended Properties='Excel 8.0;HDR=Yes;IMEX=0';" />

I am using windows app in VS


ConfigurationManager.ConnectionStrings["Excels"].ConnectionString.Replace("[Today'sDate]", DateTime.Today.ToString("fmt"))

Connection string is just string ;)


If you don't want a static value, don't put it in app.config :) Or rather, put a template in app.config, but when you create the actual data source, perform a template replacement before you create the connection. Presumably you are creating the connection yourself, so you can get in there to change the connection string?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜