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

时间:2014-03-24 18:23:28

标签: c# reportviewer windows-forms-designer

我尝试使用按钮上的点击事件通过报告查看器生成报告。它的工作正常。但是当我在数据库报告查看器中更新我的数据时只显示旧报告。我也试过使用刷新报告。没有用。我在数据集中使用表适配器来填充我的数据。 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();

1 个答案:

答案 0 :(得分:3)

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

您只需要手动定义连接,重新填充数据集并将源绑定到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();
    }