问题“我有一个DataTable,怎样获取某笔记录“?

DataTable如下:

 1  private DataTable UserInfor()
 2     {
 3         DataTable Dtable = new DataTable();
 4         Dtable.Columns.Add("ID", typeof(int));
 5         Dtable.Columns.Add("Name", typeof(string));
 6         Dtable.Columns.Add("Address", typeof(string));
 7 
 8         Dtable.Rows.Add(1, "Leo Yang", "DongGuan");
 9         Dtable.Rows.Add(2, "Peter Zhong", "GuanZhou");
10         Dtable.Rows.Add(3, "Eric Peng", "ShenZhen");
11         return Dtable;
12     }


下面分种方式来演示。
第一个是使用DataView的RowFilter()方法:
从DataTable过滤和获取某行记录


绑定至Data控件:

this.GridView1.DataSource = dv;
this.GridView1.DataBind();


第二个方法:
从DataTable过滤和获取某行记录

第三个方法:
从DataTable过滤和获取某行记录


第四个方法,其实它是第三种方法的简化版:
从DataTable过滤和获取某行记录


第二,三和第四个方法,绑定至Data控件:

this.GridView1.DataSource = query.AsDataView().ToTable();
this.GridView1.DataBind();


第五个方法,使用DataTable的Select方法,可以实现查询多个字段。
从DataTable过滤和获取某行记录


绑定至Data控件:

this.GridView1.DataSource = query.CopyToDataTable();
this.GridView1.DataBind();


第六个方法:
http://www.cnblogs.com/insus/archive/2012/08/22/2650137.html

相关文章:

  • 2022-12-23
  • 2021-08-22
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-10-19
  • 2021-07-31
  • 2022-12-23
  • 2021-05-22
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案