我对 ssrs 的子报表部分很陌生。我已经设置了一些与标准表以及矩阵和 tablix 控件配合良好的代码,但无法加载子报表。我总是得到同样的结果
有人有使用 Visual Studio 2010 的子报表的示例代码吗?
错误消息“子报表数据检索失败”。
尽管我尝试了很多不同的方案来尝试将数据传递到子报表中,但我的代码看起来像这样。
private void LoadReport(string reportName)
{
reportViewer1.Clear();
//http://social.msdn.microsoft.com/Forums/en/vsreportcontrols/thread/b039e765-3cc8-43ec-ae67-14b9656bc981
reportViewer1.Reset();
//设置处理模式
reportViewer1.ProcessingMode=ProcessingMode.Local;
//设置RDL文件
reportViewer1.LocalReport.ReportPath = 报告名称+".rdlc";
}
公共(public)无效LoadReport(IEnumerable产品,字符串报告名称,字符串数据源名称)
{
LoadReport(报告名称);
ReportParameter myParam = new ReportParameter("ReportParameter1", st.ToString() + "TO "+ et.ToString());
reportViewer1.LocalReport.SetParameters(new ReportParameter[] { myParam });
reportViewer1.LocalReport.DataSources.Add(
新的 ReportDataSource(dataSourceName, 产品));
reportViewer1.LocalReport.DataSources.Add(
new ReportDataSource(dataSourceName+"子报表", products));
//处理并渲染报告
reportViewer1.RefreshReport();
}
最佳答案
来自 Jin Chen Microsoft,版主用户奖章 msdn论坛上的答案 http://social.msdn.microsoft.com/Forums/en-US/sqlreportingservices/thread/5d2aed0b-ea69-4cbb-b3c4-b306a48fbc30
非常感谢!
我确实有这段代码,但我在表单设计器中添加了事件,这是我通过 GUI 事件属性窗口添加的
按照你的例子,我移动了这一行
reportViewer1.LocalReport.SubreportProcessing += new Microsoft.Reporting.WinForms.SubreportProcessingEventHandler(this.reportViewer1_suberport1);
从 form.designer.cs 到刷新报告后,就像您在示例中所做的那样,现在它可以工作了!!!
谢谢你,感恩节,哇
reportViewer1.RefreshReport();
reportViewer1.LocalReport.SubreportProcessing += new Microsoft.Reporting.WinForms.SubreportProcessingEventHandler(this.reportViewer1_suberport1);
private void reportViewer1_suberport1(对象发送者,SubreportProcessingEventArgs e)
{
ReportDataSource r=reportViewer1.LocalReport.DataSources[0];
e.DataSources.Add(r);
}
关于ssrs-2008 - SSRS子报表VS2010子报表数据检索失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4261970/