Report Viewer X Dapper

前端 未结 4 1816
野的像风
野的像风 2021-01-18 16:11

I\'m feeding a ReportDataSource with a query using Dapper. However, I have an empty report, even with an IEnumerable loaded data. When you spend a

4条回答
  •  醉酒成梦
    2021-01-18 16:23

    Not sure how Dapper works, but a datatable is binded like this:

    DataTable dt = new DataTable();
    DataColumn dc = dt.Columns.Add();
    dc.ColumnName = "DataColumn1";
    dc = dt.Columns.Add();
    
    dc.ColumnName = "DataColumn2";
    dt.Rows.Add(new object[] { "Frank", 32 });
    this.reportViewer1.LocalReport.DataSources.Clear();
    
    this.reportViewer1.LocalReport.DataSources.Add(new ReportDataSource("DataSet1_DataTable1", dt));
    this.reportViewer1.RefreshReport();
    

    and since I am using C#, I bind data sources like this:

    this.bindingSource1.DataSource = getListMethod(); // this method/property returns a list of objects
    this.reportViewer1.LocalReport.DataSources.Add(new ReportDataSource("Point", (this.bindingSource1)));
    //Point is the datatable name in my Dataset.xsd file
    

提交回复
热议问题