views:

1390

answers:

1

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);
        }
    }
+2  A: 

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.

Jon
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
JK