vb.net Linq实战

VB.net 提供了通过Linq对数据集进行合计非常方法,可以减少了与数据库的交互,提高系统性能,以下是sum示示例:

1、对字典对象的sum

dis.Sum(Function(a) a.Value) 'dis是Dictionary
当然也可以用

Mytb.Compute("Sum(USM_TOTAL_CASH_MONEY)", "")

2、对datatable的单字段sum

(From row In tmptable Select row.Field(Of Decimal)("customer_ds")).Sum() '
tmptable是DataTable对象,customer_ds是合计字段

3、对DataTable的多字段sum

 Dim sumtable2 = From r In MyTb
               Group r By Key = New With {Key .Key = "合计"} Into g = Group
              Select New With {.key = Key,
                               .totalMoney = g.Sum(Function(x) IIf(IsDBNull(x("A1")), 0, x("A1"))),
                               .saleMoney = g.Sum(Function(x) IIf(IsDBNull(x("A2")), 0, x("A2"))),
                               .CaSh = g.Sum(Function(x) IIf(IsDBNull(x("A3")), 0, x("A3"))),
                               .CardPay = g.Sum(Function(x) IIf(IsDBNull(x("A4")), 0, x("A4"))),
                               .OtherPay = g.Sum(Function(x) IIf(IsDBNull(x("A5")), 0, x("A5"))),
                               .CkPay = g.Sum(Function(x) IIf(IsDBNull(x("A6")), 0, x("A6"))),
                               .DyqPay = g.Sum(Function(x) IIf(IsDBNull(x("A7")), 0, x("A7"))),
                               .Minus = g.Sum(Function(x) IIf(IsDBNull(x("A8")), 0, x("A8"))),
                               .orders = g.Sum(Function(x) IIf(IsDBNull(x("A9")), 0, x("A9"))),
                               .newCards = g.Sum(Function(x) IIf(IsDBNull(x("A10").ToString().Split("/")(0)), 0, x("A11").ToString().Split("/")(0))) & "/" &
                                           g.Sum(Function(x) IIf(IsDBNull(x("A11").ToString().Split("/")(1)), 0, x("A11).ToString().Split("/")(1))),
        .cardInNums = g.Sum(Function(x) IIf(IsDBNull(x("充卡张数/金额").ToString().Split("/")(0)), 0, x("充卡张数/金额").ToString().Split("/")(0))) & "/" &
                     g.Sum(Function(x) IIf(IsDBNull(x("充卡张数/金额").ToString().Split("/")(1)), 0, x("充卡张数/金额").ToString().Split("/")(1)))
                              }

vb.net教程c#教程python基础教程

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值