简体   繁体   中英

C# rdlc date switch statement not working

=Switch(
    IsNothing(Parameters!additionalDate.Value), " ",
    len(Parameters!additionalDate.Value) <5, " ",
    len(Parameters!additionalDate.Value)>=5, CDate(Parameters!additionalDate.Value).ToShortDateString()
    )

This will throw a #Error on the report when there is no date. The date field happens to be 2 blank characters. Why would this give an error as output instead of the " "?

VBScript expressions such as switch() , iif() , and choose() don't short-circuit like they would in C#, so all your expressions in your switch statement will be evaluated, no matter what the value is.

Try to perform your validation earlier in your method/process that loads the report. If that is not possible, you have to check for all possible values/nulls in every one if your checks.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM