如何将数据源绑定到.rdlc报告在c#

编程入门 行业动态 更新时间:2024-10-28 07:32:06
本文介绍了如何将数据源绑定到.rdlc报告在c#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

朋友,我已经开发了一个简单的应用程序使用c#,它有两个rdlc报告

Friends , I have developed a simple application using c# , it has two rdlc reports

我使用下面的代码将数据源绑定到报表查看器

i used this below code to bind datasource to report viewer

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

但是当报告生成时,它是空的报告没有数据会显示,任何意见?

But when the report is generated ,it is empty report no data will displayed , any opinion???

推荐答案

当您通过向导在项目中添加.rdlc报告时,默认情况下将数据集名称设置为'DataSet1' 。现在,如果要动态绑定新数据集,则该数据集的名称必须为'DataSet1'。尝试更改它,并检查表[0]是否包含一些数据(Rows),其中 DataType 与原始dataType DataSet1 匹配。如果DataType不匹配,那么数据不会在ReportViewer中。尝试以下代码: -

When you add .rdlc report in your project by wizard then by default it take dataset name as 'DataSet1' . Now if you want to bind dynamically new dataset then name of that dataset must be 'DataSet1'. Try change it and also check that Table[0] contains some data(Rows) for which DataType get matched with original dataType of DataSet1. If DataType doesn't matches then data wont come in your ReportViewer. Try this code:-

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报告(核心逻辑)的更多详细信息,请参阅以下链接 如何创建没有数据库的报告(RDLC)?

For more detail about .rdlc report(Core logic) refer following link How to create report (RDLC) without database?

更多推荐

如何将数据源绑定到.rdlc报告在c#

本文发布于:2023-11-12 23:24:05,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1582795.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:数据源   绑定   如何将   报告   rdlc

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!