Search code examples
c#reporting-servicesssrs-2014reportparameter

Reportmigration: CrystalReports to SSRS Parameter is applied but not used


Im currently trying to migrate a report from CrystalrReports to SSRS. Im very new to reporting and havent worked with eighter one of those reporting systems before.

I have one main report, with 2 subreports. They are working correctly and showing the desired data. There are 2 parameters, the AllFields-Parameter and the SelectedId-Parameter.

AllFields tells if empty fields should be left out per datarow. SelectedId tells which datarow has been selected in the viewer, so the report can be only about that specific data.

When I debug my code, the correct parameters are applied. I have absolutely no idea why he is still processing all the data, no matter what I select.

This is the c# code beneath the report:

    public HauptformularReportForm(DataTable themen, GespraechprotokollDAO gespraechprotokollDao, GrundlagendokumenteDAO grundlagendokumenteDao, bool onlyFilledFiels, int themaId)
        : this()
    {
        themaDS = new ReportDataSource("DataSet1", themen);
        // fill themen to display
        bewertungDS = ComputeAndFillBewertungs(themen);
        // display all fields = also empty ones
        ReportParameter rp = new ReportParameter("AllFields", (!onlyFilledFiels).ToString());
        // -1 means all themen
        tid = new ReportParameter("SelectedId", themaId.ToString());
        parameterList = new List<ReportParameter>();
        parameterList.Add(rp);
        parameterList.Add(tid);
        this.crystalReportViewer.LocalReport.SetParameters(parameterList);
        this.crystalReportViewer.LocalReport.DataSources.Clear();
        this.crystalReportViewer.LocalReport.DataSources.Add(themaDS);
        this.crystalReportViewer.LocalReport.DataSources.Add(bewertungDS);
        this.crystalReportViewer.LocalReport.SubreportProcessing += new SubreportProcessingEventHandler(SetSubDataSource);
        //this.crystalReportViewer.LocalReport.Refresh();
        this.crystalReportViewer.RefreshReport();
    }

    public void SetSubDataSource(object sender, SubreportProcessingEventArgs e)
    {
        // display all fields = also empty ones
        e.DataSources.Add(themaDS);
        e.DataSources.Add(bewertungDS);
    }

    /// <summary>
    /// The report will only display the given thema
    /// </summary>
    /// <param name="themaId"></param>
    public void DisplaySingleThema(int themaId)
    {
        tid.Values.Clear();
        tid.Values.Add(themaId.ToString());
        parameterList.Add(tid);
    }

    /// <summary>
    /// Compute the average Bewertungs for all given themen, 
    /// fill a DataTable with the computed averages and use is as datasource in the report.
    /// </summary>
    /// <param name="themen"></param>
    private ReportDataSource ComputeAndFillBewertungs(DataTable themen)
    {
        HauptformularReportDataSet.BewertungDataTable bewertungDataTable = new HauptformularReportDataSet.BewertungDataTable();

        // get bewertungs of all themen
        Dictionary<int, IList<IFrageWithBewertung>> dictionary = BewertungsExtractor.Extract(themen);

        // fill table with thema_id and computed bewertung
        foreach (KeyValuePair<int, IList<IFrageWithBewertung>> themaBewertung in dictionary)
        {
            HauptformularReportDataSet.BewertungRow row = bewertungDataTable.NewBewertungRow();

            row.THEMA_ID = themaBewertung.Key;
            row.BewertungOfAllFragen = BewertungAverageComputer.ComputeAverage(themaBewertung.Value);
            row.BewertungOfFragenWithStatus = BewertungAverageComputer.ComputeAverage(themaBewertung.Value, true);

            bewertungDataTable.AddBewertungRow(row);
        }

        // set datasource in report
        report.Database.Tables["Bewertung"].SetDataSource(bewertungDataTable as DataTable);
        return new ReportDataSource("DataSet2", bewertungDataTable as DataTable);

    }
}

What have i missed or done wrong? Why is my parameter applied correctly (i see the correct value in the debugger) but still its not really used?


Solution

  • alright, the code is mostly correct, besides im giving the wrong datasources to the subreports in the upper example.

    i didnt know about filters and they werent even mentioned when i googled my problem. anyway its working now, stuff needs to be filtered per report/subreport.