ReportViewer 除以零 [英] ReportViewer Division by zero

查看:50
本文介绍了ReportViewer 除以零的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的报告中有一些公式,为了防止被零除,我在表达式字段中这样做:

I have some formulas in my reports, and to prevent divsion by zero I do like this in the expression field:

=IIF(Fields!F1.Value <> 0, Fields!F2.Value/Fields!F1.Value, 0)

=IIF(Fields!F1.Value <> 0, Fields!F2.Value/Fields!F1.Value, 0)

这通常工作正常,但是当 F1 和 F2 都为零时,我在报告中收到#Error",并收到此警告:文本框‘textbox196’的值表达式包含一个错误:尝试除法为零."

This normally works fine, but when both F1 and F2 are zero, I get "#Error" in the report, and I get this warning: "The Value expression for the textbox ‘textbox196’ contains an error: Attempted to divide by zero."

这是为什么?

推荐答案

必须有比这更漂亮的方法,但这应该有效:

There has to be a prettier way than this, but this should work:

=IIF(Fields!F1.Value <> 0, Fields!F2.Value / 
   IIF(Fields!F1.Value <> 0, Fields!F1.Value, 42), 0)

这篇关于ReportViewer 除以零的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆