web.config文件配置
<configuration>
<connectionStrings>
<add name="myCon"
connectionString="data source=.SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|你的sql数据库名称.mdf;User Instance=true"
providerName="System.Data.SqlClient" />
</connectionStrings>
<system.web> ... </system.web>
</configuration>
xxxx.aspx文件引用:
string conString = WebConfigurationManager.ConnectionStrings["myCon"].ConnectionString;
SqlConnection sqlcn = new SqlConnection(conString);
SqlCommand sqlcmd = new SqlCommand();
sqlcn.Open();
sqlcmd.Connection = sqlcn;
sqlcmd.CommandText = "select * from table";
sqlcmd.ExecuteNonQuery();
sqlcmd.Dispose();
sqlcn.Close();
sql数据库 连接 asp.net
最新推荐文章于 2024-08-22 10:10:35 发布