加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

vb.net Linq实战

发布时间:2020-12-17 07:36:08 所属栏目:百科 来源:网络整理
导读:VB.net 提供了通过Linq对数据集进行合计非常方法,可以减少了与数据库的交互,提高系统性能,以下是sum示示例: 1、对字典对象的sum dis.Sum(Function(a) a.Value) 'dis是Dictionary 当然也可以用 Mytb.Compute("Sum(USM_TOTAL_CASH_MONEY)","") 2、对datata

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")),x("A1"))),.saleMoney = g.Sum(Function(x) IIf(IsDBNull(x("A2")),x("A2"))),.CaSh = g.Sum(Function(x) IIf(IsDBNull(x("A3")),x("A3"))),.CardPay = g.Sum(Function(x) IIf(IsDBNull(x("A4")),x("A4"))),.OtherPay = g.Sum(Function(x) IIf(IsDBNull(x("A5")),x("A5"))),.CkPay = g.Sum(Function(x) IIf(IsDBNull(x("A6")),x("A6"))),.DyqPay = g.Sum(Function(x) IIf(IsDBNull(x("A7")),x("A7"))),.Minus = g.Sum(Function(x) IIf(IsDBNull(x("A8")),x("A8"))),.orders = g.Sum(Function(x) IIf(IsDBNull(x("A9")),x("A9"))),.newCards = g.Sum(Function(x) IIf(IsDBNull(x("A10").ToString().Split("/")(0)),x("A11").ToString().Split("/")(0))) & "/" &
                                           g.Sum(Function(x) IIf(IsDBNull(x("A11").ToString().Split("/")(1)),x("A11).ToString().Split("/")(1))),.cardInNums = g.Sum(Function(x) IIf(IsDBNull(x("充卡张数/金额").ToString().Split("/")(0)),x("充卡张数/金额").ToString().Split("/")(0))) & "/" &
                     g.Sum(Function(x) IIf(IsDBNull(x("充卡张数/金额").ToString().Split("/")(1)),x("充卡张数/金额").ToString().Split("/")(1)))
                              }

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读