Report Viewer with parameters. C#

Asked

Viewed 1,073 times

0

Hello!

The report (.rdlc) is successfully returning data with the help of a datatable, but I need to put parameters and it doesn’t work.

Follows the code:

 private void frmReportTeste_Load(object sender, EventArgs e)
    {
        try
        {
            // TODO: This line of code loads data into the 'dsOrcPrevisto.dtOrcPrevisto' table. You can move, or remove it, as needed.
            this.dtOrcPrevistoTableAdapter.Fill(this.dsOrcPrevisto.dtOrcPrevisto);

            ReportParameter p1 = new ReportParameter("op.venda", venda.ToString());
            ReportParameter p2 = new ReportParameter("op.vendedor", vendedor.ToString());
            this.reportViewer1.LocalReport.SetParameters(new ReportParameter[] { p1, p2 });

            this.reportViewer1.RefreshReport();
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message, "", MessageBoxButtons.OK, MessageBoxIcon.Error);
        }
    }

Displays the error:

Message = "Attempt to configure a report parameter 'op.sell' that is not defined in this report."

From what I understand, op.venda is not in the sql that fills the datatable but you are.

  • in the . rdlc editor you have to add the parameters you are passing.

  • added a table linked to datatable, but I couldn’t find the part about the parametres

  • I really like the Builder report to build reports, it’s very easy. Basically you must define a datasource, it can be a direct connection to the database or an xml file that is your case, then you must define a dataset, link the datasource to the dataset and create the Fields that will receive the parameters.

  • and the parameters in the report Builder are placed where?

  • to put parameters is the time to create table Adapter.. when you create the query you have to put the parameters in the query itself.. Example: where cliente = @cliente... if it is oracle is :cliente

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.