Reload and Refresh Report Viewer based on New RDLC File

25,848

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

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.

Share:
25,848
JK.
Author by

JK.

I like hiking and most movies.

Updated on August 30, 2020

Comments

  • JK.
    JK. almost 4 years

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

    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.

    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.

    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);
            }
        }
    
  • JK.
    JK. almost 15 years
    This worked great. Thank yo so much for the help. Very much appreciated. I just added: this.ReportViewer.Reset(); after my "generate new file" code and before my sql connection code. This was perfect thanks. J
  • LOAS
    LOAS almost 12 years
    I had the same problem for remote reports. This answer still applied. Thanks!