zoukankan      html  css  js  c++  java
  • c# DataTable select 过滤返回新DataTable

    Select();

                Select("id>='3' and name='3--hello'");//支持and

                Select("id>='3' or id='1'");//支持or

                Select("name like '%hello%'");//支持like   

                Select("id>5","id desc");

                Select("id>5", "id desc",DataViewRowState.Added)

    DataRow[] dr = dt.Select(“col='XXXX'”);//条件:就是字段名='某某'

            /// 执行DataTable中的查询返回新的DataTable

            /// </summary>
            /// <param name="dt">源数据DataTable</param>
            /// <param name="condition">查询条件</param>
            /// <returns></returns>
            private DataTable GetNewDataTable(DataTable dt, string condition,string sortstr)
            {
                DataTable newdt = new DataTable();
                newdt = dt.Clone();
                DataRow[] dr = dt.Select(condition,sortstr);

        if (dr== null || dr.Length == 0)  return null
                for (int i = 0; i < dr.Length; i++)
                {
                    newdt.ImportRow((DataRow)dr[i]);
                }
                return newdt;//返回的查询结果
            }
    ————————————————
    版权声明:本文为CSDN博主「qq1429351723」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
    原文链接:https://blog.csdn.net/qq_30469045/article/details/52105132

  • 相关阅读:
    51nod——T1267 4个数和为0
    cf220B莫队
    cf220b
    poj1436水平可见线
    poj2528贴海报,,
    poj3468
    hdu1698
    ural1989 单点更新+字符串hash
    cf Queries on a String
    hdu4605
  • 原文地址:https://www.cnblogs.com/net-sky/p/12012626.html
Copyright © 2011-2022 走看看