如何在报表查看器中使用数据表的数据

本文关键字:数据表 数据 报表 | 更新日期: 2023-09-27 17:56:50

我将datagridview的数据源作为数据表获取,并将其传递给报表查看器

        DataTable dd = (DataTable)DGVCars.DataSource;
        dd.TableName = "Cars";
        Report r = new Report(dd);
        r.Show();

       // MaterialsSuppliersDataSet t = new MaterialsSuppliersDataSet();
       // MessageBox.Show("" + dd.Rows[0][1]);
        ReportDataSource RDS = new ReportDataSource("Cars",dd);

        RV.ProcessingMode = ProcessingMode.Local;
        LocalReport lc = RV.LocalReport;
        lc.DataSources.Add(RDS);
        RV.LocalReport.ReportPath = "Report1.rdlc";
        this.RV.RefreshReport();

如何使用数据表的字段显示在报告中?

如何在报表查看器中使用数据表的数据

若要将记录绑定到报表查看器,请使用数据绑定。

this.ReportViewer1.LocalReport.ReportPath = Server.MapPath("Report1.rdlc");
ReportDataSource rds = new ReportDataSource("Cars", Dataset);
this.ReportViewer1.ProcessingMode = ProcessingMode.Local
this.ReportViewer1.LocalReport.DataSources.Clear();
this.ReportViewer1.LocalReport.DataSources.Add(rds);
this.ReportViewer1.DataBind();
this.ReportViewer1.LocalReport.Refresh();

请详细参考这篇代码项目文章。

按照以下步骤操作:

1) 在项目中添加新的类库项。

2)将数据表的列定义为此类的属性,如下面的示例:

   String _name;
   Public String name
   {
       get {return _name;}
       set {_name=Value;}
   }

3) 构建您的项目。

4) 将报表向导项添加到项目中。

5)为新的rdlc报表定义具有对象类型的数据源,然后选择您的类(在步骤1中定义)作为数据集。

现在,您可以将类的属性(与数据表的列相同)视为报表中的字段。