各位老师好,下面这段代码运行时提示:已经添加了具有相同键的项。请老师检查一下问题出在哪里,谢谢
Dim jf1 As New GroupTableBuilder("各单位差旅支出统计表", DataTables("差旅费统计表"))
jf1.Groups.AddDef("录入日期",DateGroupEnum.Year,"年份") '----按年分组
jf1.Groups.AddDef("单位","单位") '---按单位分组
jf1.Totals.AddDef("住宿_公务卡","住宿公务卡") '---Totals.AddDef是统计列,AggregateEnum.Sum是求和
jf1.Totals.AddDef("住宿_现金","住宿现金")
jf1.Totals.AddDef("公共交通费_公务卡","车piao公务卡")
jf1.Totals.AddDef("公共交通费_现金","车piao现金")
jf1.Totals.AddDef("其它_公务卡","其它公务卡")
jf1.Totals.AddDef("其它_现金","其它现金")
jf1.Build '生成统计表
DataTables("各单位差旅支出统计表").DataCols.Add("差旅支出", Gettype(Double), "IsNull([住宿公务卡],0) + IsNull([住宿现金],0) + IsNull([车piao公务卡],0) + IsNull([车piao现金],0) + IsNull([其它现金],0) + IsNull([其它公务卡],0)")
Dim jf2 As New GroupTableBuilder("各单位采购支出统计表", DataTables("日常采购统计表"))
jf2.Groups.AddDef("录入日期",DateGroupEnum.Year,"年份")
jf2.Groups.AddDef("单位","单位")
jf2.Totals.AddDef("合计金额_公务卡","采购支出")
jf2.Build '生成统计表
Dim jf3 As New GroupTableBuilder("各单位车辆支出统计表", DataTables("车辆日常加油维修保养统计表"))
jf3.Groups.AddDef("录入日期",DateGroupEnum.Year,"年份")
jf3.Groups.AddDef("单位","单位")
jf3.Totals.AddDef("加油金额_公务卡","加油公务卡")
jf3.Totals.AddDef("加油金额_现金","加油现金")
jf3.Totals.AddDef("维修金额_公务卡","维修公务卡")
jf3.Totals.AddDef("维修金额_现金","维修现金")
jf3.Totals.AddDef("保养金额_公务卡","保养公务卡")
jf3.Totals.AddDef("保养金额_现金","保养现金")
jf3.Build '生成统计表
DataTables("各单位车辆支出统计表").DataCols.Add("车辆支出", Gettype(Double), "IsNull([加油公务卡],0) + IsNull([加油现金],0) + IsNull([维修公务卡],0) + IsNull([维修现金],0) + IsNull([保养公务卡],0) + IsNull([保养现金],0)")
Dim jf4 As New GroupTableBuilder("各单位就餐支出统计表", DataTables("基层单位加班就餐统计表"))
jf4.Groups.AddDef("录入日期",DateGroupEnum.Year,"年份")
jf4.Groups.AddDef("单位","单位")
jf4.Totals.AddDef("金额_合计","就餐支出")
jf4.Build '生成统计表
'----以下是综合统计
Dim bd1 As New GroupTableBuilder("统计表h1",DataTables("各单位差旅支出统计表"))
Dim dt1 As fxDataSource
bd1.Groups.AddDef("年份") '根据年份分组
bd1.Groups.AddDef("单位") '根据单位分组
bd1.Totals.AddDef("差旅支出") '对支出金额进行统计
dt1 = bd1.BuildDataSource()
Dim bd2 As New GroupTableBuilder("统计表h2",DataTables("各单位采购支出统计表"))
Dim dt2 As fxDataSource
bd2.Groups.AddDef("年份")
bd2.Groups.AddDef("单位")
bd2.Totals.AddDef("采购支出")
dt2 = bd2.BuildDataSource()
Dim bd3 As New GroupTableBuilder("统计表h3",DataTables("各单位车辆支出统计表"))
Dim dt3 As fxDataSource
bd3.Groups.AddDef("年份","年份")
bd3.Groups.AddDef("单位")
bd3.Totals.AddDef("车辆支出")
dt3 = bd3.BuildDataSource()
Dim bd4 As New GroupTableBuilder("统计表h4",DataTables("各单位就餐支出统计表"))
Dim dt4 As fxDataSource
bd4.Groups.AddDef("年份")
bd4.Groups.AddDef("单位")
bd4.Totals.AddDef("就餐支出")
dt4 = bd4.BuildDataSource()
'----以下是组合多个统计结果(本方法是多个联接列的组合方法)
Dim nms As String() = {"年份","单位"} '指定连接列
dt1.Combine(nms,dt2,nms)
dt1.Combine(nms,dt3,nms) '代码运行到这一行报错,错误提示“已经添加了具有相同键的项”
dt1.Combine(nms,dt4,nms)
dt1.Show("统计表h1") '显示统计结果
Tables("经费支出统计_综合统计表").DataSource = dt1 '将统计结果绑定到Table
[此贴子已经被作者于2023/7/17 20:26:11编辑过]