使用对象作为数据集创建报告并通过数据表加载

时间:2018-10-13 21:53:14

标签: c# reportviewer

我在使用报表查看器创建报表时遇到了麻烦。

我无法使用报告查看器创建报告。我想通过DataTable加载它,并使用一个类作为数据集

 public  class ViewDoenca
    {
        // Classe
        private int _codigo { get; set; }
        private string _descricao { get; set; }
        private int _status { get; set; }
        private string _observacao { get; set; }

        public int codigo
        {
            get { return _codigo; }
            set { _codigo = value; }
        }

        public string descricao
        {
            get { return _descricao; }
            set { _descricao = value; }
        }

        public int status
        {
            get { return _status; }
            set { _status = value; }
        }

        public string observacao
        {
            get { return _observacao; }
            set { _observacao = value; }
        }
    }

并且我有一个.xaml文件,它是显示报告的屏幕

 public void ExibeReport(DataTable dt, string rel, string Titulo, string Filtro)
        {
            try
            {
                this._reportViewer.LocalReport.DataSources.Clear();

                ReportDataSource DTSource = new ReportDataSource("Data", dt);


                this._reportViewer.SetDisplayMode(Microsoft.Reporting.WinForms.DisplayMode.PrintLayout);
                this._reportViewer.ZoomMode = Microsoft.Reporting.WinForms.ZoomMode.Percent;
                this._reportViewer.ZoomPercent = 100;
                this._reportViewer.LocalReport.DataSources.Add(DTSource);

                _reportViewer.LocalReport.ReportEmbeddedResource = "SistemaNutricao.Relatorios." + rel;

                this._reportViewer.RefreshReport();
            }
            catch
            {
                MessageBox.Show("Ocorreu um erro ao tentar gerar o relatório, verifique se sua versão do Report Viewer está instalada e atualizada.");
            }
        }


        private void _reportViewer_Load(object sender, EventArgs e)
        {
            try
            {
                this._reportViewer.RefreshReport();
            }
            catch
            {
                MessageBox.Show("Erro ao tenta gerar relatorio! Faça download do reportviewer");
            }
        }

dt =我要传递数据的DataTable,其中包含4列(代码,描述,状态和观察) rel =在这种情况下我要使用的报告的名称是“ RelDoencas.rdlc” titulo filtro 是一些参数,但我没有使用

error displayed while generating report

creating report

0 个答案:

没有答案