Home Articles

C# - 将数据表绑定到reportviewer

Asked
Viewed 1340 times
2

我试图在运行时将 DataTable 绑定到 winforms winforms 但是我在 reportviewer 中收到此消息(不例外)“

尚未指定报告定义的来源“

这是我的代码:

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

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

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

有任何想法吗?

1 Answer

  • 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();
    

    得到了here (Codeproject)的答案 .

Related