Error while refreshing report Viewer C#

Asked

Viewed 102 times

0

I’m having a problem running a report on Viewer in c#.

The problem is the following I have to add a list in the data source, but it adds the first list, then no longer updates.

What Can Be ?

Code example.

            List<auxFertilizanteRel> lstFert = new List<auxFertilizanteRel>();
        for (int i = 0; i < ccbOpcaoFertilizante.Items.Count; i++)
        {
            if (ccbOpcaoFertilizante.GetItemChecked(i))
            {
                var listFertilizante = pFertilizante.ReturnAllByCiclo(ObjCiclo.objID, int.Parse(ccbOpcaoFertilizante.Items[i].ToString()), true);
                var vMediaFertilizantes = cFertilizante.ReturnMedia(ObjCiclo, int.Parse(ccbOpcaoFertilizante.Items[i].ToString()));
                foreach (var item in listFertilizante)
                {
                    auxFertilizanteRel list = new auxFertilizanteRel();
                    list.cabecalho = ccbOpcaoFertilizante.Items[i].ToString();
                    list.codigoEstagio = item.codigoEstagio;
                    list.objID = item.objID;
                    list.descricao = item.descricao;
                    list.kgha = item.kgha;
                    list.daedap = item.daedap;
                    list.n = item.n;
                    list.p2o5 = item.p2o5;
                    list.k2o = item.k2o;
                    list.s = item.s;
                    list.ca = item.ca;
                    list.mg = item.mg;
                    list.b = item.b;
                    list.zn = item.zn;
                    list.cu = item.cu;
                    list.mn = item.mn;
                    list.co = item.co;
                    list.mo = item.mo;
                    list.marcado = item.marcado;
                    list.IDEstagioCultura = item.IDEstagioCultura;
                    list.IDCicloProducao = item.IDCicloProducao;
                    list.IDFornecedor = item.IDFornecedor;
                    list.opcao = item.opcao;
                    list.opcaoMarcada = item.opcaoMarcada;
                    list.eficiencia = item.eficiencia;
                    lstFert.Add(list);
                }
            }
        }
   reportAnalises.LocalReport.DataSources.Add(new ("dsFertilizante", lstFert))

        this.reportAnalises.SetDisplayMode(DisplayMode.PrintLayout);
        this.reportAnalises.ZoomMode = ZoomMode.FullPage;
        this.reportAnalises.LocalReport.SetParameters(parametros);
        this.btnEnviarPdf.Enabled = true;

        this.reportAnalises.RefreshReport();
  • Tried cleaning reportAnalises.LocalReport.Datasources before adding again?

  • Yes I used at the beginning of the structure

  • I used this code "this.reportAnalises.Localreport.DataSources.Clear();" Only when I press the button to generate the report it accuses, saying that there is no data for dsFertilizante

  • Is your example correct? In Datasources.Add, are you actually adding a direct tuple? Shouldn’t it be a Reportdatasource?

1 answer

1


Add Datasource as follows:

//limpa datasources
reportViewer.LocalReport.DataSources.Clear();

//carrega relatório
using (var st = typeof(DocumentRenderer).Assembly.GetManifestResourceStream("meu_relatorio.rdlc")) {
reportViewer.LocalReport.LoadReportDefinition(st);
}

//seta datasource e faz refresh do relatório
reportViewer.LocalReport.DataSources.Add(new ReportDataSource("dsFertilizante", myCtx.ReportDataTerm));

//atualiza o relatório
reportViewer.LocalReport.Refresh();
  • @Micheloliveira good morning, I edited the answer with the solution I use here. See if this way works.

Browser other questions tagged

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