You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

VS2012 VB.NET环境下Crystal Report的Running Total Fields无Sum选项问题

错误原因

你需要汇总的Total Com字段被定义为String类型,Crystal Report仅对数值类型字段提供Sum、Average等数值汇总选项,字符串类型仅支持计数、最大/最小值等汇总逻辑,因此你找不到Sum选项。

解决步骤
  • 修改DataTable字段的数据类型,将Total Com改为数值类型(根据你的数据精度选择Integer/Decimal等),同时在写入数据时做类型转换,修改后set_cr_field方法的代码如下:
Private Sub set_cr_field()
     ' 把字段类型从String改为Decimal
     dt_report.Columns.Add("Total Com", GetType(Decimal))
    
     For Each dgr As DataGridViewRow In dgv_report.Rows
        Dim total_com as string
        total_com = dgr.Cells(25).Value.ToString
        ' 字符串转Decimal再存入DataTable,可根据需要增加TryParse做异常处理
        dt_report.Rows.Add(Decimal.Parse(total_com))
     Next
     ds_report.Tables.Add(dt_report)
     ds_report.WriteXmlSchema("cr_swastik.xml")
End Sub
  • 运行程序重新生成XML Schema文件,覆盖旧的cr_swastik.xml,保证数据源schema中该字段为数值类型。
  • 打开Crystal Report设计界面,刷新数据源绑定:找到「设置数据源位置」选项,重新关联更新后的XML Schema,确认报表侧识别到Total Com为数值类型。
  • 重新创建Running Total Fields,此时汇总选项列表就会显示Sum选项,按你的分组需求配置重置条件即可。
补充注意点

如果你的Total Com存在空值或者非数值格式的内容,建议用Decimal.TryParse做类型转换容错,避免程序运行时抛出格式转换异常。

内容的提问来源于stack exchange,提问作者Jatin Pathak

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.03 06:54:01