Wpf中的SSRS报告问题

时间:2010-06-02 13:20:15

标签: wpf reporting-services reportviewer

DataTable reportData = this.GetReportData(startId, endId, empId, minAmount, reportType);


                ReportViewer reportViewer = new ReportViewer();
                reportViewer.ProcessingMode = ProcessingMode.Local;

                reportViewer.LocalReport.ReportEmbeddedResource = "PDCL.ERP.Modules.Marketing.Reports.rptDoctorDetail.rdlc";  

                ReportDataSource ds = new ReportDataSource();
                ds.Name = "DoctorDetail_Report";
                ds.Value = reportData;
                reportViewer.LocalReport.DataSources.Add(ds);


                reportViewer.RefreshReport();
                this.WindowsFrmHost.Child = reportViewer;

这是我的代码。我正在使用SSRS,但查看者只显示但不显示任何数据。 为什么..?

2 个答案:

答案 0 :(得分:1)

我认为您需要在将reportviewer加载到视图后调用刷新报告。

这是我的代码有效(reportViewerHost是WindowsFormsHost,在UserControl中使用XAML声明)

private void UserControl_Loaded(object sender, RoutedEventArgs e)
        {
            SqlReportViewModel report = (SqlReportViewModel)this.DataContext;
            Microsoft.Reporting.WinForms.ReportViewer reportviewer = new Microsoft.Reporting.WinForms.ReportViewer();
            reportViewerHost.Child = reportviewer;
            reportviewer.ProcessingMode = Microsoft.Reporting.WinForms.ProcessingMode.Local;
            reportviewer.LocalReport.ReportPath = report.FileName;
            report.LoadReport(reportviewer.LocalReport);
            reportviewer.RefreshReport();
        }

在SqlReportViewModel的LoadReport方法中,我将数据源设置为

_report.DataSources.Add(new ReportDataSource(dataset.Name, tbl));

其中_report是对作为参数传递的LocalReport对象的引用

LocalReport _report;

我花了一段时间来弄清楚这一点......希望这会有所帮助.. 祝你好运.. :)

答案 1 :(得分:0)

ReportViewer reportViewer = new ReportViewer();
DataTable reportData = this.GetReportData(startId, endId, empId, minAmount, reportType); 
reportViewer.LocalReport.ReportPath = "Reports//abc.rdlc";
ReportDataSource ds = new ReportDataSource("DataSet1", reportData);
//DataSet1 is the datasetname of the datasource on the rdlc report
reportViewer.LocalReport.DataSources.Add(ds);
reportViewer.RefreshReport();
Reports.TReportViewer report = new Reports.TReportViewer(); 
//TReportViewer is the window of wpf application where i set the reportviewerhost.
report.reportViewerHost.Child = reportViewer;   

希望它能回答你的问题。