[我的ASP.net学习历程]DataBase Settion(5)
来源:互联网 发布:数据统计有什么用 编辑:程序博客网 时间:2024/06/10 19:39
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();
}
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();
}
- [我的ASP.net学习历程]DataBase Settion(5)
- [我的ASP.net学习历程]DataBase Settion(3)
- [我的ASP.net学习历程]DataBase Settion(4)
- [我的ASP.net学习历程]DataBase Settion(6)
- [我的ASP.net学习历程]DataBase Settion(7)
- [我的ASP.net学习历程]DropDownList
- [我的ASP.net学习历程]IsPostBack
- [我的ASP.net学习历程]out
- [我的ASP.net学习历程]Reference
- [我的ASP.net学习历程]RegularExpressionValidator
- [我的ASP.net学习历程]ArrayList用法
- [我的ASP.net学习历程]Cache和DateTime
- [我的ASP.net学习历程]DataGrid(DataBind)(1)
- [我的ASP.net学习历程]DataGrid(DataBind)(2)
- [我的ASP.net学习历程]DataGrid(PageChange)(1)
- [我的ASP.net学习历程]DataGrid(PageChange)(2)
- [我的ASP.net学习历程]DataList(DataBind)(1)
- [我的ASP.net学习历程]DataList(DataBind)(2)
- 快速配置weblogic8.X的应用目录
- [我的ASP.net学习历程]DataBase Settion(3)
- 使用 Microsoft SQL Server 2000 各种版本或组件而必须安装的操作系统
- 关于asp.net中文文件名超长的下载问题
- [我的ASP.net学习历程]DataBase Settion(4)
- [我的ASP.net学习历程]DataBase Settion(5)
- [我的ASP.net学习历程]DataBase Settion(6)
- 微软bug导致航空无线电系统崩溃3小时
- [我的ASP.net学习历程]DataBase Settion(7)
- 《水煮西游记》之三——天地合谋篇
- -- 序 --
- oledb
- 逗留汉城 (9/12)
- 飞跃太平洋 (9/12)