Foxtable(狐表)用户栏目专家坐堂 → 关于数据统计时,如果表数据为空,出现的错误


  共有3257人关注过本帖树形打印复制链接

主题:关于数据统计时,如果表数据为空,出现的错误

帅哥哟,离线,有人找我吗?
wealthwind
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:三尾狐 帖子:660 积分:3965 威望:0 精华:0 注册:2014/3/16 20:34:00
关于数据统计时,如果表数据为空,出现的错误  发帖心情 Post By:2014/5/2 13:03:00 [显示全部帖子]

菜单代码是:
MainTable = Tables("订单")
Dim Cmd As new SQLCommand
Cmd.C
Cmd.CommandText = "select distinct 分区,客户编码,客户,年,月份,目标 from 专卖店目标 where " & CustomFilter
Dim dt1 As DataTable = Cmd.ExecuteReader
Dim dtb As New DataTableBuilder("统计")
dtb.AddDef("分区", Gettype(String), 50)
dtb.AddDef("客户编码", Gettype(String), 150)
dtb.AddDef("客户", Gettype(String), 150)
Dim prds As List(of String()) = dt1.GetUniqueValues("","年","月份")
Dim exp As String
dtb.AddDef("目标总额", Gettype(Double))
dtb.AddDef("销售总额", Gettype(Double))
dtb.AddDef("达成率", Gettype(Double),"[销售总额]/[目标总额]")
For Each prd As String() In prds
    dtb.AddDef(prd(0) & "_" & prd(1) & "_目标", Gettype(Double))
    dtb.AddDef(prd(0) & "_" & prd(1) & "_销售", Gettype(Double))
    exp = String.format("[{0}]/[{1}]",prd(0) & "_" & prd(1) & "_销售" ,prd(0) & "_" & prd(1) & "_目标" )
    dtb.AddDef(prd(0) & "_" & prd(1) & "_达成率", Gettype(Double),exp)
Next
dtb.Build()
Cmd.CommandText = "select 分区,客户编码,客户,year(日期) as 年,month(日期) as 月份,sum(金额) as 销售 from 订单 where " & CustomFilter & " group by 分区,客户编码,客户,year(日期),month(日期)"
Dim dt2 As DataTable = Cmd.ExecuteReader
For Each cus As String() In dt1.GetUniqueValues("","分区","客户编码","客户")
    Dim dr As DataRow = DataTables("统计").AddNew()
    dr("分区") = cus(0)
    dr("客户编码") = cus(1)
    dr("客户") = cus(2)
    For Each prd As String() In prds
        dr(prd(0) & "_" & prd(1) & "_目标") = dt1.Compute("Sum(目标)","分区 = '" & cus(0) & "' And 客户编码 = '" & cus(1) & "' And [年] = '" & prd(0) & "' and 月份 = '"& prd(1) &"'")
        dr(prd(0) & "_" & prd(1) & "_销售") = dt2.Compute("Sum(销售)","分区 = '" & cus(0) & "' And 客户编码 = '" & cus(1) & "' And [年] = '" & prd(0) & "' and 月份 = '"& prd(1) &"'")
    Next
    dr("目标总额") = dt1.Compute("Sum(目标)","分区 = '" & cus(0) & "' And 客户编码 = '" & cus(1) & "'")
    dr("销售总额") = dt2.Compute("Sum(销售)","分区 = '" & cus(0) & "' And 客户编码 = '" & cus(1) & "'")
Next
For Each prd As String() In prds
    DataTables("统计").DataCols(prd(0) & "_" & prd(1) & "_达成率").SetFormat("0.00%")
Next
DataTables("统计").DataCols("达成率").SetFormat("0.00%")
MainTable = Tables("统计")
Tables("统计").AutoSizeCols
图片点击可在新窗口打开查看此主题相关图片如下:360截图20140502130308092.jpg
图片点击可在新窗口打开查看





如果订单表是空的话,点击菜单就会出现错误。。。。。。。。。。。。。。。。。。。。。

 回到顶部
帅哥哟,离线,有人找我吗?
wealthwind
  2楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:三尾狐 帖子:660 积分:3965 威望:0 精华:0 注册:2014/3/16 20:34:00
  发帖心情 Post By:2014/5/2 13:04:00 [显示全部帖子]

CLICK
图片点击可在新窗口打开查看此主题相关图片如下:360截图20140502130349387.jpg
图片点击可在新窗口打开查看

 回到顶部