Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>It does work but it sure is persnickety.</p> <p>First thing I recommend is to develop your reports as .rdl. Much easier to test the reports this way. You can also get the subreport parameters set up and tested as rdl, making sure each parameter of the subreport is also defined as a parameter of the parent report. Once you get the reports - including the subreports - working that way you can rename the .rdl to rdlc and add the rdlc files to your ReportViewer Project. No further changes required. Use the names of the rdl datasources as the data source names in your code to provide data to the report in the SubreportProcessing event handler.</p> <p>You don't assign values to the passed parameter. The subreport will use them as is. (Sounds like the step you are missing is adding the parameters to the parent report as well as the the subreport as mentioned above.) You can evaluate the parameters and use them as query parameters to get the datasource you will add. You have to think about the datasource like its on an undiscovered dimension for a subreport. You will have to poke around while debugging in the event handler to see what I mean. Some of the values in your application will be readily available, others that you use easily elsewhere will throw object not found exceptions. For example I create a dataset in a instance of a class created on my applications main form. I use the data set throughout my application. In the SubreportProcessing event handler I cannot use the common dataset, so I must create a new instance of the table I need for the report and populate it. In the main report I would be able to access the common dataset. There are other limitations like this. Just have to wade your way through.</p> <p>Here is the SubreportProcessing event handler from a working VB.NET ReportViewer application. Shows a few different ways to get the datasource for a subreport. subreport1 builds a one row datatable from application business objects, subreport2 provides data the report requires without a parameter, subreport3 is lie subreport2 but evaluates one of the parameters passed to the subreport for use in date value required by the query that creates the ReportDataSource. </p> <pre><code> Public Sub SubreportProcessingEventHandler(ByVal sender As Object, _ ByVal e As SubreportProcessingEventArgs) Select Case e.ReportPath Case "subreport1" Dim tbl As DataTable = New DataTable("TableName") Dim Status As DataColumn = New DataColumn Status.DataType = System.Type.GetType("System.String") Status.ColumnName = "Status" tbl.Columns.Add(Status) Dim Account As DataColumn = New DataColumn Account.DataType = System.Type.GetType("System.String") Account.ColumnName = "Account" tbl.Columns.Add(Account) Dim rw As DataRow = tbl.NewRow() rw("Status") = core.GetStatus rw("Account") = core.Account tbl.Rows.Add(rw) e.DataSources.Add(New ReportDataSource("ReportDatasourceName", tbl)) Case "subreport2" core.DAL.cnStr = My.Settings.cnStr core.DAL.LoadSchedule() e.DataSources.Add(New ReportDataSource("ScheduledTasks", _ My.Forms.Mother.DAL.dsSQLCfg.tSchedule)) Case "subreport3" core.DAL.cnStr = My.Settings.cnStr Dim dt As DataTable = core.DAL.GetNodesForDateRange(DateAdd("d", _ -1 * CInt(e.Parameters("NumberOfDays").Values(0)), _ Today), _ Now) e.DataSources.Add(New ReportDataSource("Summary", dt)) End Select End Sub </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload