I am new to the subreport part of ssrs. I have setup some code which works well with the standard tables and matrix and tablix controls but have been unable to get the subreport to load. I keep getting the same
Does anyone have any sample code of a subreport working with visual studio 2010?
error message "data retrieval failed for开发者_开发技巧 the subreport".
My code looks like this though I have tried a bunch of different scenarios to try to pass the data into the subreport.
private void LoadReport(string reportName)
{
reportViewer1.Clear();
//http://social.msdn.microsoft.com/Forums/en/vsreportcontrols/thread/b039e765-3cc8-43ec-ae67-14b9656bc981
reportViewer1.Reset();
// Set Processing Mode
reportViewer1.ProcessingMode = ProcessingMode.Local;
// Set RDL file
reportViewer1.LocalReport.ReportPath = reportName+".rdlc";
}
public void LoadReport(IEnumerable products, string reportName, string dataSourceName)
{
LoadReport(reportName);
ReportParameter myParam = new ReportParameter("ReportParameter1", st.ToString() + " TO " + et.ToString());
reportViewer1.LocalReport.SetParameters(new ReportParameter[] { myParam });
reportViewer1.LocalReport.DataSources.Add(
new ReportDataSource(dataSourceName, products));
reportViewer1.LocalReport.DataSources.Add(
new ReportDataSource(dataSourceName+"Subreport", products));
// Process and render the report
reportViewer1.RefreshReport();
}
From Jin Chen Microsoft, ModeratorUsers Medals the answer on the msdn forum http://social.msdn.microsoft.com/Forums/en-US/sqlreportingservices/thread/5d2aed0b-ea69-4cbb-b3c4-b306a48fbc30
THANK YOU SO MUCH!!!
I did have this code but I had the event added in the form designer which I added via the GUI event property window thing
and following your example I moved this line
reportViewer1.LocalReport.SubreportProcessing += new Microsoft.Reporting.WinForms.SubreportProcessingEventHandler(this.reportViewer1_suberport1);
From the form.designer.cs to after the refresh report as you did in your example and NOW IT WORKS!!!
Thank you awesome thanksgiving, whew
reportViewer1.RefreshReport();
reportViewer1.LocalReport.SubreportProcessing += new Microsoft.Reporting.WinForms.SubreportProcessingEventHandler(this.reportViewer1_suberport1);
private void reportViewer1_suberport1(object sender, SubreportProcessingEventArgs e)
{
ReportDataSource r=reportViewer1.LocalReport.DataSources[0];
e.DataSources.Add(r);
}
I did not find that moving the event handler to a different spot helped for this particular error. For this error, what fixed it is, well you have to make sure that your subreport can run stand-along without errors. THEN, tie it in to the main report. In my case my report was using a different dataset in the IDE than I was supplying it with in the code.
精彩评论