c# - 如何在 C# 中将数据源绑定(bind)到 .rdlc 报告

标签 c# winforms dataset rdlc

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] 是否包含一些 DataTypeDataSet1 的原始数据类型相匹配的数据(行)。如果数据类型不匹配,则数据不会进入您的 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/

相关文章:

c# - 如何通过 oledb reader 或 excel library、excel datareader 或 NPOI 等(Interop 除外)在 Excel 中检查单元格是否包含公式?

java - 如何访问每一行中的条目并应用自定义函数?

tensorflow - 如何有效地标记我的图像分类数据集?

c# - 未收集内存

c# - C# 中的 C++ 结构

c# - Microsoft.IdentityModel.Clients.ActiveDirectory.UserCredential 不采用 2 个参数?

performance - Linq-to-SQL 数据检索速度比较

c# - 如何使用 Spliton 和类型映射复杂对象?

c# - 覆盖 Form 的 OnFormClosing 以进行验证

c# - 在 tabcontrol C# 中搜索标签页