Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/299.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何在报表查看器中使用DataTable的数据?_C#_Winforms_Reportviewer - Fatal编程技术网

C# 如何在报表查看器中使用DataTable的数据?

C# 如何在报表查看器中使用DataTable的数据?,c#,winforms,reportviewer,C#,Winforms,Reportviewer,我将datagridview的数据源作为datatable获取,并将其传递给reportviewer DataTable dd = (DataTable)DGVCars.DataSource; dd.TableName = "Cars"; Report r = new Report(dd); r.Show(); 如何使用Datatable的字段在报表中显示?要将记录绑定到报表查看器,请使用Databind this.ReportV

我将datagridview的数据源作为datatable获取,并将其传递给reportviewer

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

如何使用Datatable的字段在报表中显示?

要将记录绑定到报表查看器,请使用Databind

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();
请详细参阅codeproject文章。

遵循以下步骤:

1在项目中添加新类库项

2将datatable的列定义为此类的属性,如下例所示:

   String _name;
   Public String name
   {
       get {return _name;}
       set {_name=Value;}
   }
3建立你的项目

4将报告向导项添加到项目中

5为新的rdlc报告定义一个对象类型的数据源,并选择在步骤1中定义为dataset的类

现在,您可以看到类的属性,这些属性与datatable中的列作为报表中的字段相同

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