如何将数据源绑定到.rdlc报告在c# [英] how to bind datasource to a .rdlc report in c#

查看:160
本文介绍了如何将数据源绑定到.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#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆