RDLC - 用空字符串替换#Error

RDLC - Replace #Error with empty string

我有一个 Tablix 用于对总计进行分组。但是,我的列数据有时可以是 stringintdecimal 等。 . 这取决于调用的存储过程。注意:这是一个动态过程。

设置 DataTable 值

var queryResult = typeof(MethodsToRdlc).GetMethod(conf.SelectMethod).Invoke(new MethodsToRdlc(), new object[] { });
DataTable result = queryResult.ToDataTable();

所以,当数据为十进制整数其他数值类型时,我想在我的 Total 中总结所有内容。为了做到这一点,我有这个非常有效的表达方式:

总表达量

=Replace(Format(Sum(CDbl(Replace(Fields!DataColumn8.Value, ",", "."))), "F"), ".", ",")

但是,当数据类型不是数字时,我得到 #Error。如何用空字符串替换 #Error(例如)?

我已经试过了:

=IIf(IsNumeric(Fields!DataColumn8.Value), Replace(Format(Sum(CDbl(Replace(Fields!DataColumn8.Value, ",", "."))), "F"), ".", ","), "")

还有这个

=IIf(IsNumeric(Replace(Fields!DataColumn8.Value, ",", ".")), Replace(Format(Sum(CDbl(Replace(Fields!DataColumn8.Value, ",", "."))), "F"), ".", ","), "")

还有这个

=IIf(CDbl(Fields!DataColumn8.Value) = 0, "", Replace(Format(Sum(CDbl(Replace(Fields!DataColumn8.Value, ",", "."))), "F"), ".", ","), "")

还有这个

=IIf(CDbl(Replace(Fields!DataColumn8.Value, ",", ".")) = 0, "", Replace(Format(Sum(CDbl(Replace(Fields!DataColumn8.Value, ",", "."))), "F"), ".", ","), "")

还有这个

=IIf(IsNothing(IsNumeric(Replace(Fields!DataColumn8.Value, ",", "."))), "", Replace(Format(Sum(CDbl(Replace(Fields!DataColumn8.Value, ",", "."))), "F"), ".", ","))

没有任何效果...总是显示 #Error.

选项 1: SSRS 不会短路 iif。即使传递了字符串值,它也会评估 true 和 false 部分。这就是它在您的表达式中导致 #Error 的原因。

用这样的东西更新 true 子句

Fields!DataColumn8.ValueIIF(IsNumeric(Fields!DataColumn8.Value),Fields!DataColumn8.Value,0)

=IIf(IsNumeric(Fields!DataColumn8.Value)
      , Replace(Format(Sum(CDbl(Replace(
       IIF(IsNumeric(Fields!DataColumn8.Value),Fields!DataColumn8.Value,0.0)
      , ",", "."))), "F"), ".", ","), "")

如果它仍然抛出错误,请尝试将您的 true 子句与 CSTR 以及 IIF 部分一起转换为 0。

选项 2: 在 SQL 查询中处理。