如何将RDLC的数据源设置为特定方法的return

How to set the datasource of RDLC to the return of a specific method

我想将我的 RDLC 报告的 datasource 设置为特定方法的 return。但是报告向导无法检测到我的方法。

方法在 Class UtilityDataLayer 命名空间中,我的报告在另一个 class 库中(FinanceReportBundle)。

Class就是这样:

namespace DataLayer
{

    public  class Utility
    {

         public static IEnumerable<object> GetAnalysisDataForConsecutiveYears(int year, int periodTypeId, int period)
        {
            ////Business
        } 
    }

 }

您不必在设计器中执行此操作。您可以轻松地在代码中设置数据源,如下所示:

var dataSource = getmyDataSource();
var rds = new ReportDataSource("myDataSourceName", dataSource);
this.reportViewer1.LocalReport.DataSources.Add(rds);
this.reportViewer1.LocalReport.ReportPath = "path your your rdlc";
this.reportViewer1.RefreshReport();