0

我正在使用以下代码更改在按钮单击事件的报表查看器控件中显示的报表。

private void ReinitializeViewer(string tsReport)
        {
            ReportDataSource ReportDataSourceX = new ReportDataSource();
            this.PurchaseReprotViewer.Reset();
            this.PurchaseReprotViewer.LocalReport.ReportEmbeddedResource = tsReport;
            if (tsReport.Contains("Rpt_PurchaseInvoice.rdlc"))
            {
                this.purchaseTableAdapter.Fill(this.gmsDataSet.purchase);
                ReportDataSourceX.Name = "PurchaseInvoiceDataSet";
                ReportDataSourceX.Value = this.gmsDataSet.Tables["purchase"];
            }
            else
            {
               ReportDataSourceX.Name = "DataSet1";

              // ReportDataSourceX.Value = Me.MyBindingSource1
            }

            this.PurchaseReprotViewer.LocalReport.DataSources.Add(ReportDataSourceX);
            //this.purchaseTableAdapter.Fill(this.gmsDataSet.purchase);
            this.PurchaseReprotViewer.RefreshReport();
        }

        private void Cmd_PurchaseInvoices_Click(object sender, EventArgs e)
        {
            ReinitializeViewer("Rpt_PurchaseInvoice.rdlc");
        }

但是我在输出中遇到了一个奇怪的错误。

在此处输入图像描述

我无法确定上述代码中出了什么问题。任何帮助表示赞赏。提前致谢。

4

1 回答 1

0

自己找到了答案。

以下代码对我有用:

private void ReinitializeViewer(string tsReport)
{
       ReportDataSource ReportDataSourceX = new ReportDataSource();
        this.PurchaseReprotViewer.Reset();

        if (tsReport.Contains("Rpt_PurchaseInvoice.rdlc"))
        {
            ReportDataSourceX.Name = "PurchaseInvoiceDataSet";
            ReportDataSourceX.Value = this.purchaseBindingSource;
            this.PurchaseReprotViewer.LocalReport.DataSources.Add(ReportDataSourceX);
            this.PurchaseReprotViewer.LocalReport.ReportEmbeddedResource = tsReport;
            this.PurchaseReprotViewer.RefreshReport();
        }

    }
于 2013-08-11T20:59:00.957 回答