C# - 将数据表绑定到reportviewer

时间:2013-06-28 19:40:06

标签: c# winforms reportviewer

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

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

这是我的代码:

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

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

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

任何想法?

1 个答案:

答案 0 :(得分: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)得到答案。