c# - 以编程方式将报告分配给我的 reportViewer

标签 c# reportviewer

我有一个报告查看器和多个报告(例如 Report1.rdlc、Report2.rdlc、ecc), 我如何以编程方式在它们之间切换?

我能够分配不同的报告,但是当我执行程序时它说我需要分配数据源,我该如何实现?

编辑:到目前为止,这是我的代码:

public Report()
{
    InitializeComponent();

    this.View_StatoMagTableAdapter.Fill(this.NGStoreV2DataSet.View_StatoMag);
    this.mag2TableAdapter.Fill(this.NGStoreV2DataSet.mag2);

    this.mag2BindingSource.DataMember = "mag2";
    this.mag2BindingSource.DataSource = this.NGStoreV2DataSet;
}

private void reportViewer1_Load(object sender, EventArgs e)
{
    this.reportViewer1.Reset();

    var binding = new BindingSource();
    binding.DataSource = this.NGStoreV2DataSet.mag2;

    ReportDataSource rds = new ReportDataSource("NGStoreV2DataSet", binding);
    this.reportViewer1.LocalReport.DataSources.Clear();
    this.reportViewer1.LocalReport.DataSources.Add(rds);
    this.reportViewer1.LocalReport.ReportEmbeddedResource = "ReportViewerForm.Report2.rdlc";
    this.reportViewer1.RefreshReport();
}

新版本仍然无法运行,当我运行程序时它仍然要求数据来源。

我已经尝试过不同的组合,但都不起作用。 组合如:

var binding = new BindingSource();
binding.DataSource = this.NGStoreV2DataSet.mag2;

ReportDataSource rds = new ReportDataSource("NGStoreV2DataSet", binding);

ReportDataSource rds = new ReportDataSourc("NGStoreV2DataSet", this.mag2BindingSource);

编辑:我终于设法解决了这个问题!!我使用了错误的数据集(NGStoreV2DataSet 而不是 DataSet1 的报告数据集) 感谢 tezzo 和 Hadi 的大力帮助;)

最佳答案

您需要同时设置ReportPathDataSources:

YourReportViewer.LocalReport.ReportEmbeddedResource = "ReportViewerForm.Report1.rdlc"
YourReportViewer.LocalReport.DataSources.Clear()
YourReportViewer.LocalReport.DataSources.Add(New ReportDataSource("YourTableName", yourDataTable))

关于c# - 以编程方式将报告分配给我的 reportViewer,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33396798/

相关文章:

c# - 图片从 HTTP 客户端上传到 C# Web Api

c# - (C#) Windows 服务中的 ReportViewer

c# - ReportViewer 报告到 PDF 文件

.net - Microsoft 报告添加两列值

wpf - 使用 WindowsformsHost 将报表查看器插入 WPF 应用程序时出现问题

c# - Azure native 客户端身份验证

c# - Entity Framework Core - 如何可编程性关闭自动增量?

sql - Crystal 报表。添加背景图片

C# 在 <form runat ="server"> </form> 中有多个客户端表单?

c# - WCF 重用 SAME 库中的类型