Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reload and Refresh Report Viewer based on New RDLC File

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);
        }
    }
like image 354
JK. Avatar asked Aug 28 '09 06:08

JK.


1 Answers

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.

like image 79
jgallant Avatar answered Nov 11 '22 03:11

jgallant