编程语言

img bgu

[我的ASP.net学习历程]DataBase Settion(5)

发表于2004/9/24 9:03:00  1086人阅读

  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();
}
阅读全文
0 0

相关文章推荐

img
取 消
img