How to pass text from textbox to report, with VS 2015, in C #?

3

I'm creating an app for the place where I work, which should print labels based on information I enter in a form I created.

For this, I'm creating a smaller version, to test if everything I want works. I'm using Visual Studio 2015 Community with files in RDLC format.

I have a form with a% name of "tb_info", and a report with a parameter named "param_info". The goal is to press the form button, it passes information from textbox to the report parameter, giving the order to print the report next.

Any idea how to do this?

    
asked by anonymous 14.10.2015 / 00:42

1 answer

4

Here is a template of an action that would return the report in PDF format, this concept addresses RDLC loading, bind with DataSource and variable assignment, I hope this is useful:

public FileResult GetRelatorio()
{
    ReportViewer report = new ReportViewer();
    report.LocalReport.DisplayName = "Relatório";

    //Carregue o rdlc do seu relatório
    using (FileStream stream = new FileStream("meu_relatorio.rdlc", FileMode.Open))
       report.LocalReport.LoadReportDefinition(stream);

    //Adicione o seu datasource
    report.LocalReport.DataSources.Add(new ReportDataSource
    {
        Name = "Nome no data source",
        Value = "Seu data source"
    });

    //Dê valor aos parâmetros do seu relatório
    ReportParameter[] parameters = new ReportParameter[]{
        new ReportParameter("Texto1", txt1.Text),
        new ReportParameter("Texto2", txt2.Text)
    };
    report.LocalReport.SetParameters(parameters);

    //Gere o seu relatório em PDF
    byte[] Arquivo = report.LocalReport.Render("PDF");
    Stream stream = new MemoryStream(Arquivo);
    return File(stream, "application/pdf");
}
    
30.06.2016 / 18:36