Zero Time Formatting in RDLC Report

I am returning time values ​​from a recordset to an RDLC report. (C # Visual Studio 2013)
They come as a nullable Timespan.
Which I show as HH: MM

This all looks ok until I get zero, if there is no time to write, it returns null, since it is a zero time type. When it does, I get #error in the RDLC report. What I want to do is either show "00:00" or just blank.

I tried adding an IFF to the Expression field in the RDLC so that if null is returned I don't show anything or "00:00" but both return the same result, #error on the field.

=IIF(IsNothing(Fields!Hours.Value),nothing,Format(TimeValue(Fields!Hours.Value.ToString),"hh:mm"))

      

Any ideas? Thank.

Solution update:

Thanks for your help: This is the final expression I used for this in my case:

=IIF(Fields!Hours.Value.ToString = "00:00:00","",Format(TimeValue(Fields!Hours.Value.ToString),"hh:mm"))

      

+3


source to share


2 answers


Try replacing the value with nothing

an empty string. Also use X is nothing

instead ISNOTHING(x)

:

=IIF(Fields!Hours.Value is nothing,"",Format(TimeValue(Fields!Hours.Value.ToString),"hh:mm"))

      



The fact that you get #error

, no matter what you tried, makes me wonder if this expression is correct or if you have something going wrong, like automatic formatting or something.

Try using this expression for the foreground color and set the color Red

in case of value null

and Green

in case it is not. Also check if you have selected any display format that might cause errors.

+1


source


You may need to use two overlapping text boxes in a container with visibility conditions based on the value of the Clock field.

A formatted Timespan could be displayed:

= Format(TimeValue(Fields!Hours.Value.ToString),"hh:mm")

      

With visibility expression (True for hidden):

= IIF(IsNothing(Fields!Hours.Value), True, False)

      



If you don't need to display any value (like "-") in the case of a null Timespan, you don't need the second textbox, but if you do, the second textbox will display your "nothing" string:

= "nothing string"

      

And the visibility expression for it would be:

= IIF(IsNothing(Fields!Hours.Value), False, True)

      

+1


source







All Articles