Web.config
<connectionStrings>
<add name="ConnectionString" connectionString="Data Source=.;Initial Catalog=asp-test;User ID=;Password=;Integrated Security=True" providerName="System.Data.SqlClient"/>
</connectionStrings>
查询测试
string
sqlconnstr=ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
SqlConnection sqlconn = new SqlConnection(sqlconnstr);
SqlCommand sqlcommand = new SqlCommand();
sqlcommand.Connection = sqlconn;
sqlconn.Open();
sqlcommand.CommandText = "select * from uesr";
SqlDataReader sqldatareader = sqlcommand.ExecuteReader();
while (sqldatareader.Read())
{
Label1.Text += sqldatareader.GetInt32(0)+"<span style='color:Red'>||||||</span>";
Label1.Text += sqldatareader.GetString(1) + "<span style='color:Red'>||||||</span>";
Label1.Text += sqldatareader.GetInt32(2) + "<span style='color:Red'>||||||</span>";
Label1.Text += sqldatareader.GetInt32(3);
};
sqlcommand = null;
sqlconn.Close();
sqlconn = null;