When trying to get a subreport to show, I found many links on the web all saying one basic thing. In order to show a sub report, you must make sure the parameters are all handled and you must also hook the SubreportProcessing
event so you can set the datasource
. The code ran fine from the report server, it was only when the report was run in LOCAL mode that it had any issues.
Here is the final solution. When you develop reports in SSBI, the reports are created with the extension of .rdl. That normally works fine when you run them, locally. But if you define subreports, they will get the "Error trying to get SubReport to show" message. Make a copy of your subreport and in that copy, change the extension from rdl ro rdlc and your problem will go away (assuming that you have the correct parameters and you are handing the SubreportProcessing
event). That is all there is to it.
#USING System.Windows.Forms
#USING System.Data
#USING ReportViewer
#using Microsoft.Reporting.Winforms
#USING wmConsulting.SFM.DataInterface
CLASS DailySalesReport INHERIT _frmReportViewer
CONSTRUCTOR()
SUPER()
RETURN
METHOD SetupReport(nUnitKey AS LONG, cDate AS STRING) AS VOID
LOCAL oReportViewer AS ReportViewer
LOCAL cReportName AS STRING
LOCAL unit_num AS ReportParameter
LOCAL sDate AS ReportParameter
LOCAL eDate AS ReportParameter
LOCAL oParameter AS ReportParameter[]
LOCAL dDate AS DateTime
LOCAL oDataObject AS Reports
LOCAL oDS AS ReportDataSource
LOCAL table AS DataTable
cReportName := "Daily Cash.rdl"
dDate := DateTime.Parse(cDate)
oDataObject := Reports{}
oDataObject:UserID := goSysInfo:UserID
table := oDataObject:GetMonthlySummary(nUnitKey,dDate,dDate)
oDS := ReportDataSource{"SFMSales",table}
unit_num := ReportParameter{"unit_num", nUnitKey:ToString()}
sDate := ReportParameter{"startDate", dDate:ToShortDateString()}
eDate := ReportParameter{"endDate", dDate:ToShortDateString()}
oParameter := ReportParameter[]{3}
oParameter[0] := unit_num
oParameter[1] := sDate
oParameter[2] := eDate
oReportViewer := SELF:ReportViewer1
oReportViewer:ProcessingMode := ProcessingMode.Local
oReportViewer:LocalReport:ReportPath := cReportName
oReportViewer:ShowParameterPrompts := FALSE
oReportViewer:LocalReport:SetParameters(oParameter)
oReportViewer:LocalReport:DataSources:Add(oDS)
oReportViewer:LocalReport:SubreportProcessing +=
SubreportProcessingEventHandler{SELF,@SubReportEventHandler()}
oReportViewer:LocalReport:Refresh()
RETURN
METHOD SubReportEventHandler(sender AS OBJECT,
e AS SubreportProcessingEventArgs) AS VOID
LOCAL oDS AS ReportDataSource
LOCAL table AS datatable
oDS := ReportDataSource{"SFMSales",Table}
e:DataSources:Add(oDS)
RETURN
END CLASS