DataGridview绑定

时间:2012-11-21 13:18:51
【文件属性】:

文件名称:DataGridview绑定

文件大小:1KB

文件格式:TXT

更新时间:2012-11-21 13:18:51

DataGridview绑定

using (SqlConnection connection = new SqlConnection(@"server=.;database=gr;user id=sa;pwd=")) { //SqlDataAdapter sda = new SqlDataAdapter("select * from customers", connection); //DataSet ds = new DataSet(); //sda.Fill(ds); BindingSource bindingSource1 = new BindingSource(); connection.Open(); SqlCommand cmd = new SqlCommand("select * from T1", connection); SqlDataReader sdr = cmd.ExecuteReader(CommandBehavior.Default); if (sdr.Read()) { bindingSource1.DataSource = sdr; GridView1.DataSource = sdr; GridView1.DataSource = bindingSource1; } }


网友评论