NDraskovic NDraskovic - 1 year ago 206
C# Question

RDLC report doesn't detect NULL values correctly

I have a problem with generating .rdlc report. One of the columns has this expression:

IIF(CInt(Fields!MyColumn.Value) = 0 or Fields!MyColumn.Value is nothing,"Unknown",Fields!MyColumn.Value)

I've also tried to use that field as a string:

=IIF(IsNothing(Fields!MyColumn.Value) or Fields!MyColumn.Value is nothing,"Unknown",Fields!MyColumn.Value.ToString())

When the value of MyColumn is not
, the report displays the value properly, but when it is
(or 0 when it's converted into int type) the report returns
. The weird thing is that when I remove the if function and display only the value of that field, the report displays 0 or blank (it doesn't return the error).
How can I fix this?

Answer Source

You could try validating without a comparison:

    , Fields!YourColumn.Value
    , "Unknown")

Or reversing your check (check if it exists, instead of checking if it doesn't exist):

=IIf(Fields!YourColumn.Value > 0
    , Fields!YourColumn.Value
    , "Unknown")

Also, I'm not sure, but it may have something to do with using different value types in the same column. Try using the same value type for an entire column. For example, only output strings, or only output ints.

If nothing works you can also check for NULL values in your code and then set the value to 0 or -1 (or so). Then in your RDLC report you can check on that.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download