我开发了一个 SSRS 报告,其中包含一个主报告和 3 个子报告。
我从 C# 调用此报告。
我只知道如何将主rdlc与数据集绑定。
我为此使用下面的代码
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();
当我运行 exe 时,我得到的报告查看器充满了主报告,但 3 个子报告显示错误,因为我没有为这些子报告指定数据源
- 主报表和其他子报表之间没有参数传递
- 主报告和所有子报告的数据集名称默认为 DataSet1
请指导我将子报告与适当的查询数据集表绑定。
我完全被困在这里了。
Edited
我用 1 个子报表更改了我的项目。
在 SSRS 中,它在(BIDS)编辑器中工作正常,但从 C# 调用时会出现错误:
在指定位置找不到。请验证子报告是否已发布且名称是否正确。
My code:
subreportevenhandler according to this question
子报表事件处理程序的问题 https://stackoverflow.com/questions/28331091/how-do-i-fill-a-dataset-in-an-ssrs-subreport
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]));
}
我仍然收到子报告错误
我将所有 .rdl 文件移至 C# bin 文件夹。
主要报告正确显示数据。在SSRS中它很好..