.net的Winform中,dataGridView数据源动态绑定!

    CSDN广告是越来越多了,所有博客笔记不再更新,新网址 DotNet笔记

大体说,这几种方式!

1:       借助DataTable

                                 

                                  DataTable Dt=new DataTable();
                                  Dt.Load(ds);   //  参数可以是SqlDataAdapter对象调用Fill()后的dataset对象,也可以是SqlDataReader对象 
                                  DataGridView.DataSource=DT;

 

2 :      借助BindSource


                                                BindingSource Bs=new BindingSource() ;
                                 Bs.DataSource=Sdr;// sdr可以是SqlDataAdapter对象调用Fill()后的dataset对象,也可以是SqlDataReader对象  
                                 DataGridView.DataSource=Bs;

3:    Linq

                        var rs= from   r  in  dataContext_name.T_table_name where ....   select r{};

                    //var rs=dataContext_name.T_table_name.Where(r=>r).Select(r=>r);

                                                 if(rs.Count()>0)

                                                 {

                                                           dataGridView1.dataSource=rs;

                                                  }

 

 

 

你可能感兴趣的:(Asp.net)