Search code examples
c#reportingrdlcsubreport

RDLC Subreport Parameters Not Working as Expected


I have an RDLC report, which displays basic information about financial transactions, and within that report I have a subreport to display the details for these transactions.

I'm having some trouble getting parameters to pass between the main and subreport. The subreport accepts one parameter: TransactionID. When I set the main report to send the actual value of TransactionID for each row, the SubreportProcessing event handler never fires, and when I try to expand the subreport, a message about a null reference exception appears in the debug output, but I cannot catch this exception to find out exactly what is null. Along with the null reference exception, the subreport displays:

Error: Subreport could not be shown

As a test, I tried to hard-code the value 0 for TransactionID, and then the SubreportProcessing event fired for every row, but with obviously incorrect results. This leads me to suspect that the TransactionID value in the rows of the main report is somehow coming up null when it tries to use it as a parameter, but I don't understand how that could be happening, or how to fix it.

Edit: Since the literal value 0 worked, I dedcided to try one of the TransactionID values from the actual report (2652791667), and found that it failed under those conditions as well. Noting that the given value exceeds the range of an Int32, I tried a smaller number, which worked.


Solution

  • The Int32 issue was the answer. I tried changing the subreport's TransactionID parameter to Text, but it apparently couldn't automatically convert the numeric value of TransactionID from the main report data to a string.

    In the end, I added a field to my dataset, called TransactionIDStr, and populated it with TransactionID.ToString(), and it now functions flawlessly.