<connectionStrings>
<add name="connstr" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Database1.mdf;Integrated Security=True;User Instance=True"/>
</connectionStrings>
在你的程序中要添加对System.Configuration的引用
string connStr = ConfigurationManager.ConnectionStrings["connStr"].ConnectionString;
using(SqlConnection conn=new SqlConnection(connStr))
{
//做相关的操作
}
希望可以帮到你 |