加入收藏 | 设为首页 | 会员中心 | 我要投稿 安卓应用网 (https://www.0791zz.com/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

DataTable的Select方法

发布时间:2020-05-27 05:28:27 所属栏目:asp.Net 来源:互联网
导读:DataTable的Select方法获取 DataRow 对象的数组。重载列表名称 说明Select() 获取所有 DataRow 对象的数组。Select(String) 按照主键顺序(如果没有主键,则按照添加顺序)获取与筛选条件相匹配的所有 DataRow 对象的数组。Select(String, String) 获取按照指

获取 DataRow 对象的数组。

重载列表 名称 说明 Select() 获取所有 DataRow 对象的数组。 Select(String) 按照主键顺序(如果没有主键,则按照添加顺序)获取与筛选条件相匹配的所有 DataRow 对象的数组。 Select(String,String) 获取按照指定的排序顺序且与筛选条件相匹配的所有 DataRow 对象的数组。 Select(String,String,DataViewRowState) 获取与排序顺序中的筛选器以及指定的状态相匹配的所有 DataRow 对象的数组。

示例:

GetRows(){ DataTable table = DataSet1.Tables[]; DataRow[] rows = table.Select(); e column of each DataRow. ( i = 0; i < rows.Length ; i++) { Console.WriteLine(rows[i][]); }}

  GetRowsByFilter(){    DataTable table = DataSet1.Tables[];        string expression;    expression =  #1/1/00#";    DataRow[] foundRows;        foundRows = table.Select(expression);        ( i = 0; i < foundRows.Length; i ++)    {        Console.WriteLine(foundRows[i][0]);    }}

GetRowsByFilter(){ DataTable table = DataSet1.Tables[]; string expression = '1/1/00'"; string sortOrder = ; DataRow[] foundRows; foundRows = table.Select(expression,sortOrder); ( i = 0; i < foundRows.Length; i ++) { Console.WriteLine(foundRows[i][0]); }}

//**********************************************************************************************************

GetRowsByFilter() { DataTable customerTable = DataTable(); customerTable.Columns.Add(,()); customerTable.Columns.Add(,(string)); customerTable.Columns[ ].Unique = ; customerTable.PrimaryKey = DataColumn[] { customerTable.Columns[] }; ( id=1; id<=10; id++) { customerTable.Rows.Add( object[] { id,string.Format(,id) }); } customerTable.AcceptChanges(); ( id=11; id<=20; id++) { customerTable.Rows.Add( object[] { id,id) }); } string expression; string sortOrder; expression = 5"; sortOrder = ; DataRow[] foundRows = customerTable.Select(expression,sortOrder, DataViewRowState.Added); PrintRows(foundRows,); foundRows = customerTable.Select(); PrintRows(foundRows,); } PrintRows(DataRow[] rows,string label) { Console.WriteLine(,label); (rows.Length <= 0) { Console.WriteLine(); ; } (DataRow row rows) { (DataColumn column row.Table.Columns) { Console.Write(,row[column]); } Console.WriteLine(); } }

(编辑:安卓应用网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读