Report Server - unable to display correct input parameter via Iif () or Switch ()

I have a null boolean input with the following expression in my textbox:

=iif(Parameters!Sorted.Value="","All",iif(Parameters!Sorted.Value="True","Sorted","Unsorted"))

      

and I am trying to display this based on the Sort parameter value

Null = "All"

True = "Sort"

False = "Unsorted"

I have also tried the following switch statement with no luck:

=Switch(Parameters!Sorted.Value="","All",Parameters!Sorted.Value="True","Sorted",Parameters!Sorted.Value="False","Unsorted")

      

Every time the report is displayed, I get the following error:

The value expression for the textbox β€˜textbox7’ contains an error: Input string was not in a correct format.

      

I am using VS2003 and SSR Designer v 8.0

Edit # 1: per request

<ReportParameter Name="Sorted">
  <DataType>Boolean</DataType>
  <Nullable>true</Nullable>
  <Prompt>Sorted</Prompt>
</ReportParameter>

      

Is this the code you requested?

+1


a source to share


3 answers


Ok, I think your problem might be that your DataType is Boolean and you are specifying an empty value. You cannot do this.

Try specifying the Nothing keyword instead:



=iif(Parameters!Sorted.Value=nothing,"All",iif(Parameters!Sorted.Value="True","Sorted","Unsorted"))

      

0


a source


If it is a Boolean parameter, it is not semantically correct to validate as if it were a string.

You can use IsNothing(Parameters!Sorted.Value)

to test for null and then Parameters!Sorted.Value = True

(no quotes) for the second case.



I'll admit that I didn't launch Visual Studio to check if it's okay to handle boolean parameters as if they were a string, but the error you're getting sounds like it. This error is usually thrown by methods Parse

, for example if you do Int32.Parse("34.32")

, or I seem to recall. I'm guessing RS is doing automatic syntax to match data types and the equality operator can do its magic.

0


a source


Why not change the logic to check explicitly for True or False and then go to "All"? And without worrying about the string, True vs "true" etc.

=iif(Parameters!Sorted.Value,"Sorted",iif(NOT(Parameters!Sorted.Value), "Unsorted","All"))

      

(Can't check and hope NOT correct :-)

0


a source







All Articles