如何在SqlDataSource中使用appSettings键

时间:2015-05-18 14:09:58

标签: c# asp.net sqldatasource

的Web.config:

<div id="content">
    <div id="area">
        <div id="bottom">bottom</div>
        <div id="middle">middle</div>
        <div id="top">top</div>
    </div>
</div>
    

ASP.net:

<appSettings file="Application.config">
        <add key="stringC" value="Data Source=svr1;Initial Catalog=myDB;Integrated Security=FALSE;user=user2;pwd=@#$123pop;" />
</appSettings>

如何使用应用程序密钥替换<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ {HOW TO USE THE APP SETTINGS KEY HERE} %>" SelectCommand="SELECT [au_id], [au_lname], [au_fname], [state] FROM [authors]" />

2 个答案:

答案 0 :(得分:3)

您可以使用<%$ ConfigurationSettings.AppSettings["stringC"] %>

<asp:SqlDataSource ID="SqlDataSource1" runat="server"
    ConnectionString="<%$ ConfigurationSettings.AppSettings["stringC"] %>"
    SelectCommand="SELECT [au_id], [au_lname], [au_fname], [state] FROM [authors]" />

答案 1 :(得分:3)

aspx中,您需要以下内容

ConnectionString="<%$ appSettings:stringC %>"