在webconfig中写好连接后,在程序中如何调用?

在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 "];

添加引用
using System.Data;
using System.Data .SqlClient ;
在类下面写数据库的引用
  private string conn= System.Configuration.ConfigurationManager.AppSettings["strConnection"].ToString();
下面就可写查询语句了
原文地址:https://www.cnblogs.com/zhanbicheng/p/6860128.html