zoukankan      html  css  js  c++  java
  • Linq对DataTable或者集合的排序,Where筛选,分组,统计总数sum等操作

    //对集合进行筛选,排序,分组

    var query = (from x in dsResult.Tables[0].AsEnumerable()
                    Where DataTrans.CBoolean(x["IsChecked"]) == true
            Group x By new
            {
                no = x.Field<string>("NO"),
                ptno = x.Field<string>("PTNO"),
                ver = x.Field<int>("VER"),
                kd = x.Field<string>("KD"),
                que_da = Convert.ToDateTime(x.Field<DateTime>("QUE_DA").ToString("yyyy/MM/dd"))
            } into g
            OrderBy g.Key.no,g.Key.ptno,g.Key.ver,g.Key.kd,g.Key.que_da
            select new
            {
                qty = g.Sum(x => Convert.ToInt32(x["QUE_QTY"])),
                stock=g.Sum(x=>Convert.ToInt32(x["STOCK"])),
                no=g.Key.no ,
                ptno=g.Key.ptno,
                ver=g.Key.ver,
                kd=g.Key.kd,
                que_da=g.Key.que_da
            });

    //统计一列的总数

    var dtUnCheckNum = objFinanceCheckDB.UnCheckNum_Get(strReportDate1);
    var queryTotal = (from DataRow row in dtUnCheckNum.Rows
                      select new { qsum = row["UnCheckNum"] }).Sum(a => Convert.ToInt32(a.qsum));
    if (queryTotal == 0)
    {
       lblWrongNum.Text = "0";
    }

    //简单按条件过滤

    var records = dt.AsEnumerable().Where(a => Convert.ToInt32(a[0]) < 1000);
    DataView rsl = records.AsDataView();
  • 相关阅读:
    C#TreeView 添加 右键快捷菜单
    Zlib Usage
    C3499 a lambda that has been specified to have a void return type cannot return a value
    Question Need to Find out
    C++ wstring转string
    C# TabPage隐藏问题
    设置IIS支持INI文件下载
    SQL SERVER CTE查询
    compression format and tools
    C++11的for循环,以及范围Range类的实现
  • 原文地址:https://www.cnblogs.com/studyC/p/2801282.html
Copyright © 2011-2022 走看看