This is a migrated thread and some comments may be shown as answers.

Passing multiple values to parameters

3 Answers 565 Views
Report Designer (standalone)
This is a migrated thread and some comments may be shown as answers.
Mando
Top achievements
Rank 1
Mando asked on 21 Aug 2017, 11:44 AM

Hello,

I'm using a standalone *.trdx report with winforms application, In the designer I defined the parameters and linked the file with a storedprocedure which requires 3 parameters (KidName, DateFrom, DateTo), and I tested from the Telerik Report Designer and it works well in the datasource wizard

 

but I cannot pass the values from the .net application

I tried this code but I always get a message Missing or Invalid parameter value. Please input valid data for all parameters

this is the code I'm using:

    uriReportSource.Parameters.Add(new Telerik.Reporting.Parameter("@KidName", KidName));
    uriReportSource.Parameters.Add(new Telerik.Reporting.Parameter("@DateFrom", DateFrom));
    uriReportSource.Parameters.Add(new Telerik.Reporting.Parameter("@DateTo", DateTo));
    uriReportSource.Parameters["@KidName"].Value = KidName;
    uriReportSource.Parameters["@DateFrom"].Value = DateFrom;
    uriReportSource.Parameters["@DateTo"].Value = DateTo;
 
reportViewer1.ReportSource = uriReportSource;
reportViewer1.RefreshReport();

 

Please fix my code and explain what I need to do

3 Answers, 1 is accepted

Sort by
0
Ivan Hristov
Telerik team
answered on 24 Aug 2017, 06:36 AM
Hello Mando,

uriReportSource.Parameters.Add(new Telerik.Reporting.Parameter("@KidName", KidName));
and
uriReportSource.Parameters["@KidName"].Value = KidName;
are doing the same thing - set a value to a parameter, except in the first line the parameter gets instantiated (the second line would throw an exception if the parameter doesn't exist already).

The problem seems to be in the parameter's name, because "@" is not a valid symbol for a parameter name. Your code should refer to a report source parameter, not to a data source parameter. Please check the name of your report parameters and use them in your initialization code.

Below is the code for initializing one of our example reports with parameters via code - the same case you're having. Please review the code and apply the changes to your project.

var uriRS = new UriReportSource() { Uri = @"C:\Program Files (x86)\Telerik\Reporting R2 2017\Report Designer\Examples\Employee Sales Summary.trdp" };
uriRS.Parameters.Add("ReportDate", "=#2003-07-01#");
uriRS.Parameters.Add("Employee", "=283");
this.reportViewer1.ReportSource = uriRS;
this.reportViewer1.RefreshReport();

Hope it helps.

Regards,
Ivan Hristov
Progress Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Mando
Top achievements
Rank 1
answered on 24 Aug 2017, 01:32 PM

Thank you Ivan for your reply

I sent the data to report via sqldatasource parameters then set the value of controls in the report code

The question now How can I transfer data from the winform to the report controls

for example if I want to print the current text boxes how can I send their values to the report

I tried this

Reports.Report1 rpt = new Reports.Report1();
rpt.ReportParameters.Add("KidName", Telerik.Reporting.ReportParameterType.String, "TestValue");
reportViewer1.ReportSource = rpt;
reportViewer1.RefreshReport();

 

and in my report:

textBox1.Value = (string)ReportParameters["KidName"].Value;

 

I dont know why the parameter is not added

0
Ivan Hristov
Telerik team
answered on 25 Aug 2017, 10:44 AM
Hello Mando,

You can set the textbox value to a parameter value using the following expression:
textBox1.Value = '=Parameters.Parameter1.Value'.
The "=" sign indicates that the value is an expression that needs to be evaluated.

In case you are creating your reports via code, please check the following articles that elaborate on the subject:

Programmatic Control of Reports
Using Report Parameters programmatically
How to: Add Report Parameters

However, we strongly recommend using the Standalone Report Designer or Visual Studio Report Designer to create your reports. The provided editors make it easier to setup styles, expressions and bindings, minimizing the errors that you could make when setting them up programmatically.

Regards,
Ivan Hristov
Progress Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
Report Designer (standalone)
Asked by
Mando
Top achievements
Rank 1
Answers by
Ivan Hristov
Telerik team
Mando
Top achievements
Rank 1
Share this question
or