单击事件里德代码
string connstr = ConfigurationManager.ConnectionStrings["ConnStr"].ConnectionString;
using (SqlConnection conn = new SqlConnection("connstr"))
app.config里面的代码
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.windows.forms jitDebugging="true" />
<connectionStrings>
<add name="ConnStr"
connectionString="Data Source=LANXIANGLIN-PC;AttachDbFilename=|DataDirectory|\Database1.mdf;Integrated Security=True;User Instance=True"/>
</connectionStrings>
</configuration>
using (SqlConnection conn = new SqlConnection("connstr"))
这里写错了,应该是:
using (SqlConnection conn = new SqlConnection(connstr))