• DataTable的Compute方法和Expression语法 拓荒者


    DataTable的Compute的功能可谓强大。

    public object Compute(
     string expression,
     string filter
    );

    expression:要执行计算的表达式

    filter:过滤表达式

    这两个表达式都是用Sql语法,例如:

    table.Compute("sum(count)", "count>0");

    当我们的table中有count和price列时,如果要计算总金额,应该如何写表达式呢?

    table.Compute("sum(count*price)", "");

    你肯定会想到这样计算,但这样是错误的。我们应该使用表达式,先添加每一行的金额列,然后再计算总金额:

    table.Columns.Add("total", typeof(decimal), "count*price");
    table.Compute("total", "");

    这个时侯才能得出总的金额。

  • 相关阅读:
    谈谈我对雾霾的看法
    2016年书单分享
    我的面试心得:面试官视角
    Cesium原理篇:GroundPrimitive
    Cesium原理篇:Batch
    Peter Hessler和他的中国三部曲(上)
    Cesium原理篇:Material
    全球PM25实时可视化
    Cesium原理篇:Property
    次郎的寿司梦
  • 原文地址:https://www.cnblogs.com/youring2/p/2524075.html
Copyright © 2020-2023  润新知