Windows窗体中的报表查看器即使在刷新报表后也不更新

本文关键字:报表 刷新 更新 窗体 Windows | 更新日期: 2023-09-27 17:52:41

我试图通过使用点击事件按钮的报告查看器生成报告。它工作得很好。但是当我在数据库报表查看器中更新数据时,只显示旧的报表。我也试过使用刷新报告。不管用。我在数据集中使用表适配器来填充我的数据。

this.reportViewer1.Reset ();
            Microsoft.Reporting.WinForms.ReportDataSource reportDataSource2 = new Microsoft.Reporting.WinForms.ReportDataSource();
            reportDataSource2.Name = "LedgerBy_partyID";
            reportDataSource2.Value = this.Ledger_by_Party_IDBindingSource;

           // this.ReportDataset.Ledger_by_Party_ID.Reset();

            this.Ledger_by_Party_IDTableAdapter.Fill(this.ReportDataset.Ledger_by_Party_ID, selected_PartyID);
            this.reportViewer1.LocalReport.ReportEmbeddedResource = "proj.userReport.Ledger_ByPartyID.rdlc";
            this.reportViewer1.LocalReport.DataSources.Clear();
            this.reportViewer1.LocalReport.DataSources.Add(reportDataSource2);
            this.reportViewer1.LocalReport.Refresh();
            this.reportViewer1.RefreshReport();

Windows窗体中的报表查看器即使在刷新报表后也不更新

我刚刚解决了同样的问题。我在网上搜索了几天,但我找不到一个好的答案。所以我希望我的帖子能帮助别人克服同样的问题。

您需要做的就是手动定义连接,重新填充数据集并将源绑定到reportviewer。下面是我的项目示例:

using Microsoft.Reporting.WinForms;
    private void ReportForm_Load(object sender, EventArgs e)
    {
        SqlConnection conn = new SqlConnection();
        conn.ConnectionString = @"Data Source=(LocalDB)'v11.0;AttachDbFilename=D:'GD Robotics'VisualProjects'GDPolin'GDPolin'PolinaDB.mdf;Integrated Security=True;Connect Timeout=30";
        conn.Open();
        SqlDataAdapter reportDBTableAdapter = new SqlDataAdapter("SELECT * FROM  [ReportDB]", conn);
        DataTable polinaDBDataSet = new DataTable();
        reportDBTableAdapter.Fill(polinaDBDataSet);
        conn.Close();
        this.reportViewer1.Reset();
        this.reportViewer1.LocalReport.DataSources.Clear();
        this.reportViewer1.LocalReport.ReportPath = @"D:'GD Robotics'VisualProjects'GDPolin'GDPolin'Report1.rdlc";
        ReportDataSource rds = new ReportDataSource("DataSet1", polinaDBDataSet);//"DataSet1" is the name of your dataset. Go to .rdlc form>VIEW>Report Data>"Right click on dataset">Dataset Properties
        this.reportViewer1.LocalReport.DataSources.Add(rds);
        this.reportViewer1.RefreshReport();
    }