DataGrid 绑定 数据库

来源:互联网 发布:淘宝网男装潮款 编辑:程序博客网 时间:2024/05/27 06:51

 

//引命名空间

using System .Data.SqlClient;

 

//连接OA

 SqlConnection con=new SqlConnection ("server=localhost;uid=sa;pwd=123;database=OA");

 

 SqlCommand cmd=new SqlCommand ("select * from t_employee",con);

 

SqlDataAdapter da=new SqlDataAdapter (cmd);

 

 DataSet ds=new DataSet ();

//填充数据集

da.Fill(ds);

this.DataGrid1.DataSource=ds;

//绑定 数据

this.DataGrid1.DataBind();

 

原创粉丝点击