1.在webconfig里面添加:
<appSettings>
<add key="connStr" value="database=InfoSite;server=.;uid=sa;pwd=stoneak47" />
</appSettings>
2.写一个DB类:
public static SqlConnection dataBaseConn()
{
SqlConnection conn=new SqlConnection((String)ConfigurationSettings.AppSettings["connStr"]);
return conn;
}
3.页面调用:
SqlConnection conn=DB.dataBaseConn();
{
SqlConnection conn=new SqlConnection((String)ConfigurationSettings.AppSettings["connStr"]);
return conn;
}