Passing Parameters to Sub Reports in RDLC Under VS 2010

18,927

Solution 1

I actually ended up figuring this out.

If you're using Visual Studio 2010 you need to go into the report definition file and make sure the Report Data window is open.

If you can't find it go to View and click on Report Data.

Once you have the window open right click on the Parameters folder and add the parameter there.

In the parameter declaration box make sure you select Allow Null Value and Allow Blank Value if it's a Text type. This should stop that error from happening.

For some reason, even though I always had a value, with local reporting it initializes the report parameter with null causing it to throw that error if you do not allow nulls/blanks.

Solution 2

Nobody seems to understand that the sub-report data needs to be shown /filtered based on the main report column values. Sorry for complaining but after spending quite a time, I figured this out.

We need to define report parameters as mentioned above in the subreport, we need to pass the parameter values to the datasource used by sub-report to display the subreport data. Given below is the snippet.. I have used ObjectDataSource to populate the subreport.

Public Sub SubreportProcessingEventHandler(ByVal sender As Object, ByVal e As SubreportProcessingEventArgs)
   'e.Parameters.Item(0) is the report parameter defined in Sub-report
    ObjectDataSource2.SelectParameters("Param1") = New Parameter("Param1", DbType.Int32, e.Parameters.Item(0).Values(0))         
     ObjectDataSource2.SelectParameters("Param2") = New Parameter("Param2", DbType.String, e.Parameters.Item(1).Values(0))
    e.DataSources.Add(New ReportDataSource("SubReportDataSourceName", ObjectDataSource2))
End Sub
Share:
18,927
Philter
Author by

Philter

Updated on June 17, 2022

Comments

  • Philter
    Philter almost 2 years

    Currently I'm working on a reporting website in VS 2010 using ASP.Net 4.0 and the 2010 RDLC designer. The report I'm building is similar to a Master-detail report, but I'm trying to do it with nested tables.

    My issue is that I'm trying to pass a field value from my main report to a sub report. The table setup looks something like this:

    2 Tables

    First Table: [RecordID, Name, Date,] Second Table: [RecordID, Description, DueDate]

    What I want to do is a table like this:

    -------------------
    |  Name  |  Date  |
    ------------------------------------
       |  Description1 |  DueDate      |
    ------------------------------------
       |  Description2 |  DueDate      |
    ------------------------------------
    | Name2 | Date2 |
    -----------------
    

    With the entries for Description and DueDate bieng part of the sub report.

    When I try to pass the RecordID in to the subreport as a parameter, which I have to manually define in the XML of the subreport because I can't find anywhere in the designer UI that will allow me to add report parameters to RDLC files, I get an error from the main report that says:

    An error occurred during local report processing.
    Value cannot be null. Parameter name: value 
    

    So it appears to be erroring out before it ever reaches the point where it does the subreport loading.

    I am getting data sent to the main report just fine, and if I remove the parameter from the subreport the data comes through. But if I add the parameter the report throws the error.

    Does anyone have any ideas on what might be causing this?

  • Paul Chavez
    Paul Chavez almost 13 years
    Thanks @Philter. I was experiencing the same problem and your answer got me close enough to realize I had a typo mis-match in the parameter names between the parent and child reports. Note: I did not have to set Allow Null Value nor Allow Blank Value to get my parameter value to pass through.
  • Philter
    Philter over 12 years
    Good idea, I forgot to mention that in my original question. It seem like subreports in general are pretty clunky in SRSS.
  • Philter
    Philter over 12 years
    Good addition, but that's not really pertinent to the issue that this question pertained to. Most any tutorial on local sub reports with parameters will tell you that you have to supply them to the sub report. The problem was that due to the type of the parameters they needed to be allowed to be null and blank, even though discrete values were being provided.
  • Shruti Kapoor
    Shruti Kapoor almost 11 years
    Hi, could you please give the above code in C#? I have the same problem and I need to filter my dataset for subreport based on report parameter. Thank you!