2

I'm trying to bind a DataTable to a reportviewer in winforms at runtime but I get this message in the reportviewer (not an exception)"

The source of the report definition has not been specified"

Here's my code:

this.rptViewer.LocalReport.DataSources.Clear(); 

ReportDataSource rprtDTSource = new ReportDataSource(dt.TableName, dt); 

this.rptViewer.LocalReport.DataSources.Add(rprtDTSource); 
this.rptViewer.RefreshReport(); 

any Ideas?

4

1 回答 1

2

试试这个:

var reportDataSource1 = new ReportDataSource { Name = "WpfApplication17_User", Value = _users };
string exeFolder = System.IO.Path.GetDirectoryName(Process.GetCurrentProcess().MainModule.FileName);
_reportViewer.LocalReport.ReportPath =exeFolder + @"\Reports\Report1.rdlc";
_reportViewer.LocalReport.DataSources.Add(reportDataSource1);
_reportViewer.RefreshReport();

从这里 (Codeproject)得到了答案。

于 2013-06-28T19:41:40.010 回答