Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/274.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何轻松否定MS Report中的表达式?_C#_Vb.net_Visual Studio 2010_Reporting Services_Crystal Reports - Fatal编程技术网

C# 如何轻松否定MS Report中的表达式?

C# 如何轻松否定MS Report中的表达式?,c#,vb.net,visual-studio-2010,reporting-services,crystal-reports,C#,Vb.net,Visual Studio 2010,Reporting Services,Crystal Reports,我正在将af Crystal报告转换为MS报告。 我在水晶报告中的表达是这样的: =IIF(Fields!foo.Value Is Nothing and Fields!bar.Value Is Nothing, 0, IIF(Fields!foo.Value Is Not Nothing and Fields!bar.Value Is Nothing, Fields!foo.Value, IIF(Fields!foo.Value Is Nothing and Fields!bar.Value

我正在将af Crystal报告转换为MS报告。 我在水晶报告中的表达是这样的:

=IIF(Fields!foo.Value Is Nothing and Fields!bar.Value Is Nothing,
0,
IIF(Fields!foo.Value Is Not Nothing and Fields!bar.Value Is Nothing,
Fields!foo.Value,
IIF(Fields!foo.Value Is Nothing and Fields!bar.Value Is Not Nothing,
Fields!bar.Value * -1,
IIF(Fields!foo.Value Is Not Nothing and Fields!bar.Value Is Not Nothing,
Fields!foo.Value,
0
))))
Not
在这里不起作用,即使文本是蓝色的

我可以使用
而不是
或类似的
还是我必须疯狂地使用
IsNothing()

试试这个:

=IIF((Fields!foo.Value.Equals(System.DBNull.Value)), "YES", "NO")
=IIF((Fields!foo.Value is System.DBNull.Value), "YES", "NO")

哦,我想出来了,我只需要把
而不是
移到表达式的开头。
这是我的VB.NET语法错误。来自C#,VB.NET和MS报告对我来说是新的,我很抱歉

=IIF(Fields!foo.Value Is Nothing and Fields!bar.Value Is Nothing,
0,
IIF(Not Fields!foo.Value Is Nothing and Fields!bar.Value Is Nothing,
Fields!foo.Value,
IIF(Fields!foo.Value Is Nothing and Not Fields!bar.Value Is Nothing,
Fields!bar.Value * -1,
IIF(Not Fields!foo.Value Is Nothing and Not Fields!bar.Value Is Nothing,
Fields!foo.Value,
0
))))

您应该能够将表达式简化为:

IIF(Not Fields!foo.Value Is Nothing, 
    Fields!foo.Value,
    IIF(Not Fields!bar.Value Is Nothing,
        Fields!bar.Value * -1,
        0))
编辑:若要在两者都不为空时返回foo.Value-bar.Value,请尝试:

= IIF(Not Fields!foo.Value Is Nothing, Fields!foo.Value, 0) -
  IIF(Not Fields!bar.Value Is Nothing, Fields!bar.Value, 0)

然后我就可以使用IsNothing方法了。我只需要像C#=IIF中的“!”(not(Fields!foo.Value是System.DBNull.Value),“YES”,“NO”)?huh:)如果xyz不是空的话,你也可以使用
形式
非常感谢。还有一件事你只需要学一次就可以永远使用:)谢谢马克,我明天会测试。你说得对,我可以减少。但是我在写问题的时候犯了一个错误。如果foo和bar都不是null,那么我要返回的值是(foo.value-bar.value)。所以我不能再修改我的代码了,但你的答案比我的好。:)@radbyx:请参阅我编辑过的答案,以获得一个简化公式,当两者都不为空时,返回foo.Value-bar.Value。