gpt4 book ai didi

c# - 如何以编程方式更改 rdlc 报告中的数据表

转载 作者:太空宇宙 更新时间:2023-11-03 22:01:01 24 4
gpt4 key购买 nike

我有以下问题。我制作了一个为我的一位客户生成 rdlc 报告的应用程序。我使用 TableAdapters 来填充我在这些报告中使用的数据表。问题是我的客户有一个新数据库,他希望能够使用该应用程序从旧数据库和新数据库生成报告。我认为可以更改我的 TableAdapter 使用的连接,以便它们只从我的客户选择的数据库中获取数据(两个数据库具有相同的模式),但我被告知这是不可能的。那么是否可以更改rdlc报告使用的DataTable?我该如何解决这个问题

最佳答案

您可以使用以下代码在运行时将任何数据表分配给 rdlc。

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

关于c# - 如何以编程方式更改 rdlc 报告中的数据表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10124047/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com