Question

I have the following method:

private void GetTransactions(string rptType, string acadYrs)
    {
        rptData = new Transactions();
        ds = new DataSet();
        ds = rpt.GetTenantContractListByYear(acadYrs);
        rds = new ReportDataSource("DataSetTenantContract", ds.Tables[0]);
        reportViewer1.LocalReport.DataSources.Add(rds);

        //Load report
        LoadReport(rptType);

        //Assign report
        reportViewer1.LocalReport.ReportPath = reportPath;

        //set report parameters
        this.SetReportParameters(acadYrs);

        //refresh report
        reportViewer1.RefreshReport();
    }

i have a method that return a LINQ result, so how can i fill the dataset with LINQ query and replace

ds = rpt.GetTenantContractListByYear(acadYrs);

with

ds = rpt.GetDataFromLINQ(acadYrs);
Was it helpful?

Solution

One of the overloads for ReportDataSource is:

public ReportDataSource(string name, IEnumerable dataSourceValue)

Assuming the result of your LINQ statement is a list (it usually is), just assign it directly:

rds = new ReportDataSource("DataSetTenantContract", rpt.GetDataFromLINQ(acadYrs));

OTHER TIPS

Add a new dataset to your project. Add a datatableadapter for this dataset and set the query for this adapter the query of your LINQ.

if Dasaset1 is your dataset name then:

private void GetTransactions(string rptType, string acadYrs)
    {

        //set report parameters
        this.SetReportParameters(acadYrs);

        //refresh report
        reportViewer1.RefreshReport();
       this.DataTable1TableAdapter.Fill(this.DataSet1.DataTable1);
    }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top