Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to add parameters in report viewer?

HY! I have a form application in visual studio 2010 and I want to create a report with report viewer and to add some parameters. I tried to add parameters from code but it didn`t work. I have this error:

FilterExpression expression for the tablix ‘Tablix1’ refers to the field ‘datastart’. Report item expressions can only refer to fields within the current dataset scope or, if inside an aggregate, the specified dataset scope. Report2.rdlc : error rsParameterReference: The FilterValue expression for the tablix ‘Tablix1’ refers to a non-existing report parameter ‘datastart’.

In my code a do this:

 private void SetReportParameters()
    {
        ReportParameter[] parameters = new ReportParameter[2];
        parameters[0] = new ReportParameter("datastart", dateTimePickerStartRaport.Text);
        parameters[1] = new ReportParameter("dataStop", dateTimePickerStopRaport.Text);
        this.reportViewer1.LocalReport.SetParameters(parameters);
    }

and after calling this method a make a refresh on the report viewer

 reportViewer1.RefreshReport();           

I also look at other forums and I saw that I have to add the parameters to the report, but I didn`t manage out how must I do this. I also tried to add, in the properties windows of the report, some filters with value

  =Parameters!datastart.Value     

but this also didn`t work.

like image 880
user599977 Avatar asked Feb 24 '11 11:02

user599977


2 Answers

The error you get is because you try to specify your parameter like a field. In the expression-designer you have a special category called "Parameters". From there you can access your parameters. The syntax is =Parameters![FieldName].Value. In your case for example =Parameters!datastart.Value.

Additionaly, note that the parameters must be declared in the "Report Data"-window under "Parameters". Its the same window as you use to declare your recordsets, however there is also a special category for parameters. There are also some options for the datatype and if specification of the parameter is mandatory.

like image 159
HCL Avatar answered Sep 28 '22 04:09

HCL


So when you create report definition (rdl or rdlc file) you have to add parameters with exactly the same names. So for your case you have to add datastart and dataStop parameters. To do it just click Parameters in Report Data Window and click add new.

like image 32
ravenik Avatar answered Sep 28 '22 05:09

ravenik