friend 们,我用c#开发了一个简单的应用程序,它有两个rdlc报告
我使用下面的代码将数据源绑定(bind)到报表查看器
this.reportViewer1.LocalReport.ReportPath = @"C:\Documents and Settings\Administrator\My Documents\Visual Studio 2008\Projects\reports\reports\Report1.rdlc";
reportViewer1.LocalReport.DataSources.Clear();
reportViewer1.LocalReport.DataSources.Add(new ReportDataSource("customer", dt.Tables[0])) ;
this.reportViewer1.RefreshReport();
但是生成报表的时候是空报表,没有数据显示,有什么意见???
最佳答案
当您通过向导在您的项目中添加 .rdlc 报告时,默认情况下它采用数据集名称作为 'DataSet1' 。现在,如果您想动态绑定(bind)新数据集,则该数据集的名称必须是 'DataSet1'。尝试更改它并检查 Table[0] 是否包含一些 DataType 与 DataSet1
的原始数据类型相匹配的数据(行)。如果数据类型不匹配,则数据不会进入您的 ReportViewer。试试这个代码:-
string exeFolder = (Path.GetDirectoryName(Application.StartupPath)).Substring(0, (Path.GetDirectoryName(Application.StartupPath)).Length - 3);
string reportPath = Path.Combine(exeFolder, @"Reports\SessionReport.rdlc");
Microsoft.Reporting.WinForms.ReportDataSource rds = new Microsoft.Reporting.WinForms.ReportDataSource("DataSet1", yourDataSet.Tables[0]);
this.reportViewer1.LocalReport.DataSources.Add(rds);
this.reportViewer1.LocalReport.ReportPath = reportPath;
this.reportViewer1.RefreshReport();
有关 .rdlc 报告(核心逻辑)的更多详细信息,请参阅以下链接 How to create report (RDLC) without database?
关于c# - 如何在 C# 中将数据源绑定(bind)到 .rdlc 报告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15894416/