對不起,如果這是一個虛擬的問題,但它真的讓我大失所望。如何在網點的aspx頁面上使用聲明的變量
我已在web.conf
<appSettings>
<add key="DBHost" value="myserver.com"></add>
<add key="DBName" value="myDBName"></add>
<add key="DBLogin" value="myDBLogin"></add>
<add key="DBPassword" value="myDBPass"></add>
<!--DBTrustedConnection: true then Connection string will be used else user and password is required-->
<add key="DBTrustedConnection" value="true"></add>
<add key="DBConnectionString" value="Data source=.\sqlexpress; Initial Catalog=DQMF; Integrated Security=True"></add>
.....other settings
</appSettings>
這裏的連接字符串我試圖使用
<form id="form1" runat="server">
<% string con="";
if(System.Configuration.ConfigurationManager.AppSettings.Get("DBTrustedConnection").Equals("true"))
con = System.Configuration.ConfigurationManager.AppSettings.Get("DBConnectionString");
else {
string DBHost = System.Configuration.ConfigurationManager.AppSettings.Get("DBHost");
string DBName = System.Configuration.ConfigurationManager.AppSettings.Get("DBName");
string DBLogin = System.Configuration.ConfigurationManager.AppSettings.Get("DBLogin");
string DBPassword = System.Configuration.ConfigurationManager.AppSettings.Get("DBPassword");
con = "Data Source=" + DBHost + ";Initial Catalog=" + DBName + ";User ID=" + DBLogin + ";Password=" + DBPassword + ";";
}
%>
<asp:SqlDataSource runat="server" ConnectionString="<%=con %>??? How to use con variable here" SelectCommand="SELECT COMMAND" ID="SqlDataSource1"></asp:SqlDataSource>
代碼這裏的問題是我不能夠使用CON變量。請幫我或暗示一些其他的方式,因爲我完全新的asp的
感謝您的幫助,我使用後面的代碼在onload函數中傳遞數據源..現在它工作正常。再次感謝 – Iftikhar