locked
RDLC Report Parameters RRS feed

  • Question

  • I have a report which is a simple list. I am trying to pass a string to give search criteria information as part of the header.

    I have created the parameter in the report using the "Report Data" option in the "View" menu. It is defined as "Parms" there. My code is as follows:

    ReportParameter Parms = new ReportParameter();
    Parms = new ReportParameter("Title", Title); //Title = string variable
                   
    ReportDataSource DS = new ReportDataSource();
    DS.Name = "DataSetName";
    DS.Value = DataTable;
    
    reportViewer1.Reset();                
    reportViewer1.ProcessingMode = ProcessingMode.Local;
    reportViewer1.LocalReport.SetParameters(Parms);
    reportViewer1.LocalReport.DataSources.Clear();
    reportViewer1.LocalReport.DataSources.Add(DS);
    reportViewer1.LocalReport.ReportPath = "ReportName.rdlc";
    reportViewer1.RefreshReport();
    
    

    When I run the report (which ran correctly before I started adding this "title line" parameter) I get a "Missing Report Source Exception" message. It does not seem to be seeing "the source of the report definition". Which I take to mean the parameter is not passing correctly.

    In the TextBox in the report definition that will hold the parameter value, the expression is "[@Parms]".

    I presume I am missing something simple and basic. Can anybody see it? Much appreciated.

    • Moved by Tina-Shi Thursday, September 18, 2014 2:33 AM the issue is not VS general issue
    Tuesday, September 16, 2014 7:10 PM

Answers

  • Apparently, you have to process the ReportPath first, THEN process SetParameters. So, the code should be as follows:


    string rptName = "Assign RDLC path and file name";
    var Title = "Create Title string";
    
    ReportParameter RP = new ReportParameter("Title", Title);
    ReportDataSource DS = new ReportDataSource("DataSet", R2);
    
    reportViewer1.Reset();
    reportViewer1.ProcessingMode = ProcessingMode.Local;
    reportViewer1.LocalReport.DataSources.Clear();
    reportViewer1.LocalReport.DataSources.Add(DS);
    reportViewer1.LocalReport.ReportPath = rptName;
    reportViewer1.LocalReport.SetParameters(RP);
    reportViewer1.RefreshReport();
    
    

    • Edited by wodders Thursday, September 18, 2014 6:31 PM
    • Marked as answer by wodders Thursday, October 2, 2014 2:12 PM
    Thursday, September 18, 2014 6:27 PM

All replies

  • Perhaps “[@Parms]” should be changed to “[@Title]”. Or maybe you should set the ReportPath before adding parameters.

    See also:

    Wednesday, September 17, 2014 5:01 AM
  • If I change "@Parms" to "@Title", I get an error message about a "non-existing parameter".

    If I move the "SetParameters" line below the "ReportPath" line, I get a "Local Processing Exception" error message. I tired moving the "SetParameters" line to between the "DataSource" add and the "ReportPath" and I get the original error message.

    I will take a closer look at the link you gave.

    Wednesday, September 17, 2014 1:19 PM
  • Just for verification purposes, I commented out the "SetParameters" line and removed the text box that held the parameter (@Parms) reference. The report ran without error.
    Wednesday, September 17, 2014 2:56 PM
  • Hi wodders,

    Thank you for posting in the MSDN forum.

    Since it is related to the Report, we will move this case to the Visual Studio Report Controls forum, you will get better support for the issue.

    Thanks for your understanding.

    Best Regards,


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place. Click HERE to participate the survey.


    • Edited by Tina-Shi Thursday, September 18, 2014 2:32 AM
    Thursday, September 18, 2014 2:32 AM
  • Apparently, you have to process the ReportPath first, THEN process SetParameters. So, the code should be as follows:


    string rptName = "Assign RDLC path and file name";
    var Title = "Create Title string";
    
    ReportParameter RP = new ReportParameter("Title", Title);
    ReportDataSource DS = new ReportDataSource("DataSet", R2);
    
    reportViewer1.Reset();
    reportViewer1.ProcessingMode = ProcessingMode.Local;
    reportViewer1.LocalReport.DataSources.Clear();
    reportViewer1.LocalReport.DataSources.Add(DS);
    reportViewer1.LocalReport.ReportPath = rptName;
    reportViewer1.LocalReport.SetParameters(RP);
    reportViewer1.RefreshReport();
    
    

    • Edited by wodders Thursday, September 18, 2014 6:31 PM
    • Marked as answer by wodders Thursday, October 2, 2014 2:12 PM
    Thursday, September 18, 2014 6:27 PM