I developed an SSRS report having a main and 3 subreport. I am calling this report from C#. I only know how to bind the main rdlc with the data set.
I use the code below for this
SqlDataAdapter dataAdapter = new SqlDataAdapter(sqlcomm);
dataAdapter.Fill(dataset);
this.reportViewer1.LocalReport.ReportPath = Application.StartupPath + "\\sale_dept.rdl";
this.reportViewer1.LocalReport.DataSources.Clear();
this.reportViewer1.LocalReport.DataSources.Add(new Microsoft.Reporting.WinForms.ReportDataSource("DataSet1", dataset.Tables[0]));
this.reportViewer1.RefreshReport();
when I run the exe i am getting the report viewer filled with main report but 3 subreport shows error because i didn't specify the DataSource for those subreports
- There is no parameter passing between the main and other sub reports
- The dataset name for the main and all sub report is default as DataSet1
Please guide me to bind the sub reports with appropriate query dataset tables. I am totally stuck here.
Edited
I changed my project with 1 subreport.
In SSRS it is working fine in (the BIDS) editor but when calling from C# it is giving error:
Could not be found at the specified location. Please verify that the subreport has been published and that the name is correct.
My code:
subreportevenhandler according to this question
question for subreport event handler
SqlDataAdapter dataAdapter = new SqlDataAdapter(sqlcomm);
dataAdapter.Fill(dataset);
this.reportViewer1.LocalReport.ReportPath = Application.StartupPath + "\\sale_dept.rdl";
this.reportViewer1.LocalReport.DataSources.Clear();
this.reportViewer1.LocalReport.SubreportProcessing +=
new SubreportProcessingEventHandler(addsubreport);
this.reportViewer1.LocalReport.DataSources.Add(new Microsoft.Reporting.WinForms.ReportDataSource("DataSet1", dataset.Tables[0]));
this.reportViewer1.RefreshReport();
void addsubreport(object sender, SubreportProcessingEventArgs e)
{
SqlConnection conn = new SqlConnection(source);
DataSet dataset = new DataSet();
conn.Open();
SqlCommand sqlcomm = new SqlCommand( "Query for subreport", conn);
SqlDataAdapter dataAdapter = new SqlDataAdapter(sqlcomm);
dataAdapter.Fill(dataset);
e.DataSources.Add(new ReportDataSource("DataSet1", dataset.Tables[0]));
}
Still I am getting error for subreport I moved all the .rdl file to C# bin folder..
Main report is showing the data correctly. In SSRS its fine..
I found out the issue. I am posting it as answer because it may help someone in future.
The
SubreportProcessingEventHandler
will only get fired for.rdlc
subreports. In my project main report and all subreports are.rdl
extension. So only change I done was went to command prompt and renamed the subreport extension as.rdlc
eg:-
ren discount.rdl discount.rdlc
Then attach the data-set for the sub-report accordingly.
See the code as below
Switch is needed if you have more than one sub-report. Main point to notice
2.if any parameter is passing make sure it is also named correctly.
Now run the C# application it will show the main report with all sub-report