C# 基于新的 RDLC 文件重新加载和刷新报表查看器

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1345373/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 15:25:31  来源:igfitidea点击:

Reload and Refresh Report Viewer based on New RDLC File

c#.netreporting-servicesreportviewerrdlc

提问by JK.

I have written a C# program using VS 2008 that uses the built in Report Viewer and processes reports locally.

我已经使用 VS 2008 编写了一个 C# 程序,该程序使用内置的报告查看器并在本地处理报告。

When the report is being viewed I want to replace the current rdlc file with a new one and refresh the report without closing the report form that contains the report viewer.

在查看报告时,我想用新的文件替换当前的 rdlc 文件并刷新报告而不关闭包含报告查看器的报告表单。

I have already checked to make sure the file is being generated properly. If I close the form with report viewer and open it back up the new file information shows. I just can't figure out how to reload the report viewer without closing the parent form.

我已经检查过以确保文件正确生成。如果我用报表查看器关闭表单并打开它备份新文件信息显示。我只是不知道如何在不关闭父窗体的情况下重新加载报表查看器。

Below is what I tried already. I get no error messages. The report appears to refresh, but it really just shows me what I was already looking at. The new RDLC file is not loaded.

下面是我已经尝试过的。我没有收到错误消息。该报告似乎刷新了,但它实际上只是向我显示了我已经在查看的内容。未加载新的 RDLC 文件。

private void BtnRefreshRpt_Click(object sender, EventArgs e)
    {

        try
        {

            GenerateNewRDLC GN = new GenerateNewRDLC();
            GN.generateFile();  /*this part definitely works*/


            SqlConnection conReport = new SqlConnection     (ConfigurationManager.ConnectionStrings["Connection String Info"].ConnectionString);
            SqlCommand cmdReport = new SqlCommand();
            SqlDataReader drReport;
            DataSet dsReport = new AdvEdgeDataSet();

            conReport.Open();

            cmdReport.CommandType = CommandType.Text;
            cmdReport.Connection = conReport;
            cmdReport.CommandText = strRptCriteria;

            drReport = cmdReport.ExecuteReader();

            dsReport.Tables[0].Load(drReport);

            drReport.Close();
            conReport.Close();

            reportViewer1.LocalReport.ReportPath = strRptResource.ToString();


            ReportDataSource rds = new ReportDataSource();
            rds.Name = strRptDataSource;
            rds.Value = dsReport.Tables[0];
            reportViewer1.LocalReport.DataSources.Add(rds);
            reportViewer1.RefreshReport();
            reportViewer1.SetDisplayMode(DisplayMode.PrintLayout);

            //this.reportViewer1.RefreshReport();

        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message);
        }
    }

采纳答案by jgallant

Try calling ReportViewer.Reset() prior to loading the new report file.

在加载新报告文件之前尝试调用 ReportViewer.Reset()。

I currently doing exactly this in my ReportViewer control, however, the source code is at work. If the Reset does not work, I will post my code here on Monday morning. It can definitely be done.

我目前在我的 ReportViewer 控件中正是这样做的,但是,源代码正在运行。如果重置不起作用,我会在周一早上在这里发布我的代码。绝对可以做到。