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..
SubReport Properties > General > Use this report as subreport
– Anup Agrawal