【问题标题】:two reports in one reportViewer一个报表查看器中的两个报表
【发布时间】:2014-05-08 03:40:35
【问题描述】:

我有一个名为 reportviewer1 的报告查看器 和两个报告(report1.rdlc、report2.rdlc) 我想通过使用代码在组合框中选择其中一个来将它们显示到reportviwer1中 我尝试了以下代码

 reportViewer1.LocalReport.DataSources.Add(new ReportDataSource("DataSet1"));

reportViewer1.LocalReport.ReportEmbeddedResource = "university_project.Report1.rdlc";

        reportViewer1.LocalReport.Refresh();

但是没用 代码的正确格式是什么?ReportDataSource 中是否缺少参数?

【问题讨论】:

    标签: c# dataset visual-studio-2013 reportviewer


    【解决方案1】:

    您需要指定记录的来源(填充数据集)并设置reportViewer的LocalPath:

    var dataSet = new DataSet();
    using (var connection = new SqlConnection("ConnectionString")) 
    {
        var sqlAdapter = new SqlDataAdapter("SELECT * FROM TABLE1",connection); // Get the records
        sqlAdapter.Fill(dataSet, "Table1");
    }
    ReportViewer1.Reset();
    ReportViewer1.LocalReport.Path = "university_project.Report1.rdlc"; // Path to your report file            
    var dataSource = new ReportDataSource("ReportDataSet_Name", dataSet.Tables[0]); // Specify report's dataset name and the records it use
    ReportViewer1.LocalReport.DataSources.Clear(); // Clean the sources so you can use different datasources each time
    ReportViewer1.LocalReport.DataSources.Add(datasource);
    ReportViewer1.LocalReport.Refresh();
    

    【讨论】:

      【解决方案2】:

      你也需要传递DataTable:

      reportViewer1.LocalReport.DataSources.Add(new ReportDataSource("DataSet1", myDataTableWithData));

      【讨论】:

        猜你喜欢
        • 2021-02-16
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-09-01
        • 1970-01-01
        • 2011-10-23
        • 1970-01-01
        • 2010-12-20
        相关资源
        最近更新 更多