Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / SSRS

SSRS - Error: Subreport could not be shown

5.00/5 (2 votes)
13 Nov 2011CPOL 43.2K  
Error trying to get SubReports to show (code in Vulcan.net)

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.


C++
// This is the Vulcan.net language - xbase to the next level
#USING System.Windows.Forms
#USING System.Data
#USING ReportViewer
#using Microsoft.Reporting.Winforms
#USING wmConsulting.SFM.DataInterface	// this is the business classes

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

    // set up report parameters
    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    

    // configure the reportviewer
    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
    // fill table here with the appropriate data
    oDS                 := ReportDataSource{"SFMSales",Table}
    e:DataSources:Add(oDS)
    RETURN
// ******************************************************************            
END CLASS

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)