protected System.Web.UI.WebControls.DataGrid DataGrid1;
private void Page_Load(object sender, System.EventArgs e)
{
// 写法一:
// string connectionString = "SERVER=172.24.17.134;USER ID=sa;PWD=testPass;DATABASE=TestDb";
// 写法二:
// string connectionString = "SERVER=HD-SERVER;USER ID=sa;PWD=testPass;DATABASE=TestDb";
// 写法三:
// string connectionString = "SERVER=(local);USER ID=sa;PWD=testPass;DATABASE=TestDb";
string connectionString = "SERVER=(local);USER ID=sa;PWD=testPass;DATABASE=TestDb";
string strSQL = "SELECT * FROM Table_1";
SqlConnection conn = new SqlConnection(connectionString);
SqlCommand cmd = new SqlCommand(strSQL,conn);
cmd.Connection.Open();
SqlDataReader dr = cmd.ExecuteReader();
DataGrid1.DataSource = dr;
DataGrid1.DataBind();
cmd.Dispose();
dr.Close();
cmd.Connection.Close();
cmd.Connection.Dispose();
}