zoukankan      html  css  js  c++  java
  • 筛选dataTable数据的2种方法

    1:

    DataView dv = new DataView() { Table = dt, RowFilter = wherecode,Sort = orderby}; //不要再排序  例如:wherecode = “did not in(‘1’,‘2’)”
    return dv.ToTable();

    2:Linq

        linq本质上只能查到IEnumable类型。所以,DataTable有一个扩展方法:AsEnumerable。

                var vdt = from temp in dt.AsEnumerable()      // linq语句  
                          where temp["CompanyName"].ToString().StartsWith(args)
                          select new
                          {  // 集合列表Eval()方法绑定的显示字段;
                              Comid = temp["Comid"].ToString(),
                              CompanyName = temp["CompanyName"].ToString(),
                              NCID = temp["NCID"].ToString(),
                              CreateDate = temp["CreateDate"].ToString(),
                              Phone = temp["Phone"].ToString()
                          };
                this.Repeater1.DataSource = vdt;
                this.Repeater1.DataBind();
     
      又例如:
     var a = from row in dt.AsEnumerable()                    

    where row.Field<int>("age") <= 24                    

    select row.Field<string>("name");

    foreach (var s in a)

  • 相关阅读:
    MyEclipse配置DataBase Explorer
    Eclipse 如何设置注释的模板
    游戏开发技术
    static_cast 与reinterpret_cast
    一个人的成功取决于晚上的8点至10点经典语录必读
    发送消息给线程
    转载ofstream和ifstream详细用法
    Effective STL笔记
    Making your C++ code robust
    TGA文件
  • 原文地址:https://www.cnblogs.com/PeaCode/p/3863521.html
Copyright © 2011-2022 走看看