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

标签 c# database-connection rdlc

我有以下问题。我制作了一个为我的一位客户生成 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/

相关文章:

具有 MySQL 数据库和部署的 C# 应用程序

java - Oracle 和 MS SQL Server 之间的桥梁

c# - 当外键为空时,使用 Lambda 表达式在 List<T> 中排序

c# - DataContractSerializer 和反序列化 Web 服务响应类型

node.js - Mongoose db find方法之前的 Node 功能整理

reporting-services - ReportViewer 创建的报告在 Excel 中显示错误消息

data-binding - 我可以在运行时创建 RDLC 和数据绑定(bind)表而不在设计时创建数据集吗?

c# - Windows UI 中的 ListView 缓存?

c# - 如何使用 LINQ 对序列中的相同值进行分组?

c# - rdlc 报告分组数据按数字列排序