1

I want to put all my sql queries in app.config.

I also know how to config

<connectionStrings>
   <add name="DatabaseConnection" 
        connectionString="Data Source=SQLEXPRESS;uid=npsa;pwd=Password1;Initial Catalog=local;" 
        providerName="System.Data.SqlClient" />
</connectionStrings>

I know how to connect to database.

Is this possible?

4

1 回答 1

3

Like most of the comments above, my answer is "WHY????"

However, assuming you really wanted to and for some reason it was a good idea to do it this way and that you'd worked out how to manage security, then you could add keys to your appsettings e.g.:

<appSettings>
    <add key="Query1" value="Select 1 from somewhere" />
</appSettings>

and then in your code you could just pull them out and execute them

var sqlString = System.Configuration.ConfigurationManager.AppSettings["Query1"];

But again, why you would want to do this escapes me.

于 2013-11-15T05:47:09.963 回答