Passing multiple values to parameters

4 posts, 0 answers
  1. Mando
    Mando avatar
    14 posts
    Member since:
    Apr 2009

    Posted 21 Aug Link to this post

    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

  2. Ivan Hristov
    Admin
    Ivan Hristov avatar
    117 posts

    Posted 24 Aug Link to this post

    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
  3. Mando
    Mando avatar
    14 posts
    Member since:
    Apr 2009

    Posted 24 Aug in reply to Ivan Hristov Link to this post

    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

  4. Ivan Hristov
    Admin
    Ivan Hristov avatar
    117 posts

    Posted 25 Aug Link to this post

    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
Back to Top