如何更改RDLC报告编程数据表 [英] How to change DataTables in rdlc reports programmatically
问题描述
我有以下问题。我做了我的一个客户产生RDLC报表的应用程序。我用的TableAdapter来填补我在这些报告使用的数据表。问题是,我的客户端有新的数据库,他希望能够使用该应用程序,以生成从两个旧的和新的报告。我认为这是可能改变我的TableAdapter的使用,使他们只取我的客户选择(这两个数据库有相同模式的)数据库中的数据,但我被告知,不能完成连接。那么,有可能改变RDLC报告使用数据表?
我怎样才能解决这个问题。
I have a following problem. I made an application that generates rdlc reports for one of my clients. I used TableAdapters to fill the DataTables that I use in those reports. The problem is that my client has a new database and he wants to be able to use that application to generate reports from both the old and the new one. I thought it was possible to change the connection that my TableAdapters use so that they would just take the data from the database that my client selects (both databases have identical schema's) but I was told that that cannot be done. So is it possible to change the DataTable that rdlc report uses? How can I solve this problem
推荐答案
您可以将任意数据表中使用下面的代码在运行时RDLC。
You can assign any datatable to rdlc at run time using following code.
DataTable dtTest =obj.SelectDepartment(1);//Here I am selecting the data from DB
this.reportViewer1.RefreshReport();
reportViewer1.Visible = true;
ReportDataSource rds = new ReportDataSource();
reportViewer1.Reset();
reportViewer1.ProcessingMode = ProcessingMode.Local;
LocalReport rep = reportViewer1.LocalReport;
rep.Refresh();
rep.ReportEmbeddedResource = "Report.rdlc";//Provide full path
rds.Name = "DataSet1_tblAdapter";//Provide refrerence to data set which is used to design the rdlc. (DatasetName_TableAdapterName)
rds.Value = dtTest;
rep.DataSources.Add(rds);
this.reportViewer1.RefreshReport();
这篇关于如何更改RDLC报告编程数据表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!