在webconfig中写,key也相当于name
<configuration>
<appSettings>
<add key= "strConnection " value= "server=localhost;database=northwind;user=sa;pwd=hello; "> </add>
</appSettings>
</configuration>
在各代码文件中调用
private string strConnection=System.Configuration.ConfigurationSettings.AppSettings[ "strConnection "];