问题描述
大家好我在c#
中有这行代码我一直收到此错误=>
语法错误:'&'运算符之前缺少操作数。
以下是我的代码感谢任何建议
Hi guys I have this line of code in c#
I keep getting this error=>
Syntax error: Missing operand before '&' operator.
Find below is my code thanks for any advice
< ds.Tables[0].Columns.Add("RESULTS").Expression = "Iif(((ActualWeight >= (.96 * TargetWeight)) And (ActualWeight <= (1.04 * TargetWeight))),'GOOD',And (ActualWeight < (0.96 * TargetWeight))),'BAD', And (ActualWeight > (1.04 * TargetWeight))) 'BAD',null)";/pre>
推荐答案
Iif(((ActualWeight >= (.96 * TargetWeight)) And (ActualWeight <= (1.04 * TargetWeight))), 'GOOD', Iif(ActualWeight < (0.96 * TargetWeight), 'BAD', Iif(ActualWeight > (1.04 * TargetWeight), 'BAD', null)))
将表达式放在多行上可能会使事情变得更清晰:
Putting the expression on multiple lines might make things clearer:
Iif(
((ActualWeight >= (.96 * TargetWeight)) And (ActualWeight <= (1.04 * TargetWeight))),
'GOOD',
Iif(
ActualWeight < (0.96 * TargetWeight),
'BAD',
Iif(
ActualWeight > (1.04 * TargetWeight),
'BAD',
null
)
)
)
编辑:正如Maciej Los指出的,你可以简化公式,这样你就不需要嵌套 Iif
秒。有关详细信息,请参阅解决方案#3。
As Maciej Los pointed out, you can simplify the formula so that you don't need nested Iif
s. See solution #3 for details.
="Iif((ActualWeight > .96 * TargetWeight) And (ActualWeight <= 1.04 * TargetWeight),'Good','Bad');
没有必要定义嵌套的iif's。如果ActualWeight为Bigger Then ...而LessOrEqual则为...... - 则条件为真,否则为false。
There is no need to define nested iif's. If ActualWeight is Bigger Then ... and LessOrEqual then ... - then condition is true, else false.
这篇关于如何在表达中使用Iif Stament的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!