Formatting null time in RDLC report

随声附和 提交于 2019-12-10 18:18:14

问题


I am bringing back time values from a record set into an RDLC report. (c# Visual Studio 2013)
They are coming is as a nullable Timespan.
Which i display as HH:MM

This all looks fine until i get a null , if there is no time for record a null is returned,as it's a nullable timespan type. When this happens i get an #error in the RDLC report. What i want to happen is either show "00:00" , or just blank.

I have tried adding an IFF to the Expression field in RDLC so that if a null is returned i show nothing , or "00:00" , but both return the same result , a #error in the field.

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

Any ideas ? Thanks.

Solution update:

Thanks for all your help : This is the final expression i used to get this working in my case:

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

回答1:


Try replacing the nothing value with an empty string. Also use X is nothing instead of 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 whether the expression is correct at all or if you have something going on in addition, like automatic formatting or stuff like that.

Please try to use this expression on the foreground color and set the color to Red in case the value is null and Green in case it is not. Also check whether there's some display format selected that could cause errors.




回答2:


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

One would display your formatted Timespan:

= 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 some value (like "-") in case of null Timespan, you don't need second text box, but if you do - second text box would display your "nothing" string:

= "nothing string"

And visibility expression for it would be:

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



回答3:


Thorsten Dittmar's solution worked for me but I think the key is to remove the TimeValue or DateValue expressions in the IIF.

I was originally doing the same to return a Date or Time and then using the Textbox format option to add the formatting. However, when the field value is Null, TimeValue or DateValue returned an error, suggesting the iif statement evaluates both results regardless.

Anyway, this works (for me):

=iif(Fields!DateRequired.Value is nothing, nothing, Format(Fields!DateRequired.Value,"HH:mm"))


来源:https://stackoverflow.com/questions/27796302/formatting-null-time-in-rdlc-report

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!