Johnny
Johnny

Reputation: 1575

SSRS Report problem in wpf

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;

this is my code.I'm using SSRS but the viewer only shows but not any data. Why..?

Upvotes: 5

Views: 1684

Answers (2)

Mudassar Farooq
Mudassar Farooq

Reputation: 106

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;   

hope it will answer your question.

Upvotes: 0

Bhuvan
Bhuvan

Reputation: 1573

I think you need to call refresh report after the reportviewer is loaded into the view.

Here is my code which works (reportViewerHost is WindowsFormsHost, declared in UserControl using 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();
        }

in the LoadReport Method of the SqlReportViewModel, I am setting the datasource as

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

where _report is the reference to LocalReport object passed as an argument

LocalReport _report;

It took me a while to figure this out... hope this helps.. Good Luck..:)

Upvotes: 2

Related Questions