我使用VS 2008编写了一个C#程序,它使用内置的Report Viewer并在本地处理报告.
在查看报表时,我想用新的rdlc文件替换当前的rdlc文件并刷新报表而不关闭包含报表查看器的报表.
我已经检查过以确保正确生成文件.如果我使用报表查看器关闭表单并将其打开备份,则会显示新的文件信息.我只是无法弄清楚如何在不关闭父表单的情况下重新加载报表查看器.
以下是我已经尝试过的.我没有收到任何错误消息.该报告似乎更新了,但它实际上只是告诉我我已经在看什么.未加载新的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); } }