使用前置代码调用数据库
我使用windows身份验证登录sqlserver
在前置代码中添加
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:db_StudentConnectionString %>"
SelectCommand="SELECT * FROM [tb_StuInfo]"></asp:SqlDataSource>
在web.config 中添加
<connectionStrings>
<add name="db_StudentConnectionString" connectionString="Data Source=WUHONGXING-PC;Initial Catalog=mydatabase;Integrated Security=true;" providerName="System.Data.SqlClient"/>
</connectionStrings>
使用后置代码调用数据库
后置代码中添加
string myStr = ConfigurationManager.AppSettings["ConnectionString"].ToString();
SqlConnection myConn = new SqlConnection(myStr);
在web.config 中添加
<appSettings>
<add key="ConnectionString" value="Server=WUHONGXING-PC;Database=mydatabase;Integrated Security=true;"></add>
</appSettings>