none
getting the parameter from the main report into a subreport RRS feed

  • Question

  • I have tried to find the answer to my question in the other posts but I cant seem to find it.

    I have a main report rdlc with one data source. I want to pass the customer name to a sub report rdlc so the sub report rdlc can display it again. In the main report rdlc I drop a sub report control into a list and point it at my sub report rdlc. I go into the sub report properties for the control on the main report, click parameters, add, set name = customer_name_parm and select the column "employee_name" from the data source to set the value and click OK.

    I also have a textbox in the list on the main report and I went into text box properties, action add customer_name_parm, value = "employee_name", and specified the go to report name as cust_sub_report (rdlc implied) and clicked OK.

    Now I switch over to the other report named cust_sub_report (rdlc) that is my sub report and in the designer I drop a text box inside a rectangle. I try to find the parameter I added in the main report rdlc but I can not find it to link them together or map them to each other. In my sub report designer I try to add a parameter named cust_name_parm and when I drop down value no dataset column is visible to select, i.e. I am looking for the column named "employee_name" from the available from the main existing dataset so I can get it's value from the same dataset/datasource passed into this sub report. I have been looking for the parameter I set up in main in a list somewhere in the sub report designed but I cannot seem to locate it. I need the textbox to point to the correct parameter.

    We are Visual Studio 2013 Update 1

    What am I missing?

    Bruce


    • Edited by Bmayfield Friday, June 13, 2014 9:30 PM
    Friday, June 13, 2014 9:07 PM

Answers

  • After some trial and error I got something that works (there may be other ways). We made sure the datasource and datasets were set up right in the main and sub reports. In the main report we added a subreport control and set the name in "Use this report as a subreport" making sure all the mixed case characters in the name matched. The name of the report displays in the subreport box after clicking OK. Click on the parameters and added a row. Set the name to PARM and clicked on the Fx icon. Under category look for fields (dataset name) and click on that. On the right pane, scroll through the field values and double click on one, you should get "=Fields!ID.Value" in the expression window on the top window. Clicked OK. Column shows up under value on subreport parameters window. Click OK. Went to the subreport.rdlc and in the report data window and right clicked on parameters, add parameter. Typed in the name as PARM, left data type as text. Should see @PARM in left pane. Set up a SubreportProcessingEventHandler in code as documented here:

    http://msdn.microsoft.com/en-us/library/microsoft.reporting.winforms.localreport.subreportprocessing.aspx

    Since we are using Oracle we wanted to retrieve the same row that the main report was processing and redisplay the content differently. so we accessed the PARM from "e As SubreportProcessingEventArgs" like this:

     mySqlCommand1.Parameters.Add(":P1", Oracle.DataAccess.Client.OracleDbType.Varchar2)
     mySqlCommand1.Parameters(":P1").Value = e.Parameters("PARM").Values(0).ToString

    We read the database row into a datatable and passed it back using this:

    e.DataSources.Add(New ReportDataSource("Report2dataSet", dt2))

    in the event handler using the link above for help. Seems to work OK.

    Sure there is probably other ways to do it but we are marking this thread as answered for now.

    Bruce

    • Marked as answer by Bmayfield Thursday, June 19, 2014 2:05 PM
    Thursday, June 19, 2014 2:05 PM