none
Problem in printing the parameters of a textbox at the rdlc reportviewer RRS feed

  • Question

  • Hi folks, is me again, asking for your help.

    I'm getting an error during the printing of report, when I input the parameters.

    I want that the report file, rdlc shows the parameters at the maskedtextbox1 and maskedtextbox2 to be printed as placed at the header.

    I' got an error message: 

    Microsoft.Reporting.WinForms.LocalProcessingException:  'Occurred an error during the processing the local report'.

    Inner Exception

    "UnknownReportParameterException: attempt to configure a report parameter  '01/08/2019 00:00:00'  that is not defined in this report."

    I just want to print the parameter inicial data and final date. The report is working very well, but whithout passing the parameters to be printed.

    Here follows the code.

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows.Forms;
    using Microsoft.Reporting.WinForms;
    
    namespace SGFRenaissance
    {
        public partial class FrmRel_TitulosaPagaremAberto : Form
        {
            public FrmRel_TitulosaPagaremAberto()
            {
                InitializeComponent();
            }
    
            private void FrmRel_TitulosaPagaremAberto_Load(object sender, EventArgs e)
            {
    
                this.reportViewer1.RefreshReport();
               
            }
    
            private void btn_executar_Click(object sender, EventArgs e)
            {
                DateTime datainicio = Convert.ToDateTime(maskedTextBox1.Text);
                DateTime datafim = Convert.ToDateTime(maskedTextBox2.Text);
                this.Numero_Parcelas_a_PagarTableAdapter.Fill(this.Rel_NumeroParcelaaPagar.Numero_Parcelas_a_Pagar, datainicio, datafim);
                this.reportViewer1.LocalReport.SetParameters(new Microsoft.Reporting.WinForms.ReportParameter(datainicio.ToString(), datafim.ToString())); // Here gets the error. Without this line the report works fine.
                this.reportViewer1.RefreshReport();
            }
        }
    }
    

    My question is simple. How to print the parameters already working "datainicio" and "datafim" (inicialdate and finaldate) translated. I put two textbox at the rdlc and added parameter expression but the Parameters didnot work.

    The expression is: "=Parameters!ReportParameter1_DataInicio.Value.ToString"

    Please help me with that. Thanks in advance.

    • Moved by CoolDadTx Friday, September 13, 2019 1:58 PM Winforms related
    Friday, September 13, 2019 3:29 AM

All replies

  • When creating a new ReportParameter, the first argument is its name and the second is its value. So you need two ReportParameters, something like so.

    ReportParameter[] parameters = new ReportParameter[2];
    parameters[0] = new ReportParameter("datainico", datainicio.ToString());
    parameters[1] = new ReportParameter("datafim", datafim.ToString());
    this.reportViewer1.LocalReport.SetParameters(parameters);
    So we set the parameter called "datainicio" to the value in the datainicio variable, and similar for datafim. That's assuming the parameters have been set to those names in the report viewer.


    • Edited by Ante Meridian Friday, September 13, 2019 4:23 AM typo.
    Friday, September 13, 2019 4:23 AM
  • Hi Ante good morning,

    Thank you for your reply.

    I did all changes you suggested and it did not work.

    I'm posting again the code that I have modified and the the error message. 

    The problem continues, the parameters are not identified by the reportviewer.

    Can you help me with that?

    Thank you very much for your attention.

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows.Forms;
    using Microsoft.Reporting.WinForms;
    
    namespace SGFRenaissance
    {
        public partial class FrmRel_TitulosaPagaremAberto : Form
        {
           
            public FrmRel_TitulosaPagaremAberto()
            {
                InitializeComponent();
            }
    
            private void FrmRel_TitulosaPagaremAberto_Load(object sender, EventArgs e)
            {
    
                this.reportViewer1.RefreshReport();
               
            }
    
            private void btn_executar_Click(object sender, EventArgs e)
            {
                DateTime datainicio = Convert.ToDateTime(maskedTextBox1.Text);
                DateTime datafim = Convert.ToDateTime(maskedTextBox2.Text);
                ReportParameter[] parameters = new ReportParameter[2];
                parameters[0] = new ReportParameter("datainicio", datainicio.ToString());
                parameters[1] = new ReportParameter("datafim", datafim.ToString());
                this.reportViewer1.LocalReport.SetParameters(parameters);
                this.Numero_Parcelas_a_PagarTableAdapter.Fill(this.Rel_NumeroParcelaaPagar.Numero_Parcelas_a_Pagar, datainicio, datafim);
                this.reportViewer1.LocalReport.SetParameters(new Microsoft.Reporting.WinForms.ReportParameter(datainicio.ToString(), datafim.ToString()));
                this.reportViewer1.RefreshReport();
            }
        }
    }
    

    Saturday, September 14, 2019 2:12 PM
  • Hi F.oliverarocha,

    Thank you for posting here.

    According to your code, I find there is no rdlc information in your code.

    Therefore, I think you could try to add the following code to see if it works.

          this.reportViewer1.LocalReport.ReportPath = "";

    Best Regards,

    Jack


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, September 16, 2019 7:42 AM
  • Jack thank your for you help.

    I Included your code, but it didn't work.

    Still the same problem. 

    Lets keep trying.

    Tuesday, September 17, 2019 1:37 AM
  • Hi 

    I find the following link may be helpful, I think you could try to add datasource in your code.

    https://forums.asp.net/t/1472608.aspx

    Best Regards,

    Jack


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.


    Tuesday, September 17, 2019 5:57 AM
  • Jack Thank you for your reply.

    I have a question for you:

    How or where do I get the "path" for the code you have sent ? Where is that path?

     this.reportViewer1.LocalReport.ReportPath = "";

    Let's see if it is the solution.

    Thanks and regards.

    Wednesday, September 18, 2019 2:19 AM
  • Hi F.oliveirarocha,

    Thanks for the feedback.

    >>How or where do I get the "path" for the code you have sent ? Where is that path?

    The path is for the rdlc file you should create.

    You need to add the following rdlc item then find the path.

    Best Regards,

    Jack


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, September 18, 2019 5:45 AM
  • Jack, 

    This file is already in the project. 

    Thanks for your reply.

    Friday, September 20, 2019 12:10 PM