【问题标题】:Enter data in the report dataset在报表数据集中输入数据
【发布时间】:2018-09-27 07:18:12
【问题描述】:

我必须在 Visual Studio 2017 上使用 reportviewer 生成报告,但是当我生成报告时出现以下错误,我还输入了 C# 代码。我还添加了 XSD 和 RDLC 文件的屏幕截图。为什么会出现这个错误?

XSD 文件截图: https://imgur.com/a/rfx24M3

RDLC 文件截图: https://imgur.com/a/AkNmBUL

错误: 尚未为数据源“DataSetArticoli”提供数据源

C# 代码:

public ReportViewer StampaDDT(DDT oggettoDDT, List<Articolo> ListaArticoli)
        {
            try
            {
                //Creazione DataTable Articoli
                DataTable dt = new DataTable();
                dt.Clear();
                dt.TableName = "DataSetArticoli";
                dt.Columns.Add("CodArt");
                dt.Columns.Add("Descrizione");
                dt.Columns.Add("UM");
                dt.Columns.Add("Quantita");

                foreach (var item in ListaArticoli)
                {
                    object[] o = { item.CodiceArticolo, item.Descrizione, item.UM, "" + item.GetQuantita() };
                    dt.Rows.Add(o);
                }
                ReportDataSource source = new ReportDataSource("DataSetArticoli", dt);
                this.r.LocalReport.DataSources.Add(source);
                this.r.LocalReport.Refresh();
                this.r.RefreshReport();
                //Fine DataTable
                this.r.LocalReport.EnableExternalImages = true;
                ReportParameterCollection reportParameters = new ReportParameterCollection
                {
                    new ReportParameter("Aspetto",oggettoDDT.GetAspetto() ?? "")
                };

                ReportParameterCollection reportParameters2 = new ReportParameterCollection
                {
                     new ReportParameter("Data",oggettoDDT.GetData() ?? "")
                };

                ReportParameterCollection reportParameters3 = new ReportParameterCollection
                {
                     new ReportParameter("Note",oggettoDDT.GetNote() ?? "")
                };

                ReportParameterCollection reportParameters4 = new ReportParameterCollection
                {
                     new ReportParameter("Trasporto",oggettoDDT.GetTrasporto() ?? "")
                };
                ReportParameterCollection reportParameters5 = new ReportParameterCollection
                {
                     new ReportParameter("Causale",oggettoDDT.GetCausale() ?? "")
                };
                ReportParameterCollection reportParameters6 = new ReportParameterCollection
                {
                     new ReportParameter("Porto",oggettoDDT.GetPorto() ?? "")
                };
                ReportParameterCollection reportParameters7 = new ReportParameterCollection
                {
                     new ReportParameter("Peso",oggettoDDT.GetPeso() ?? "")
                };
                ReportParameterCollection reportParameters8 = new ReportParameterCollection
                {
                     new ReportParameter("Colli",oggettoDDT.GetColli() ?? "")
                };
                ReportParameterCollection reportParameters9 = new ReportParameterCollection
                {
                     new ReportParameter("DescrizioneVettore",oggettoDDT.GetDescrizioneVettore() ?? "")
                };

                this.r.LocalReport.SetParameters(reportParameters);
                this.r.LocalReport.SetParameters(reportParameters2);
                this.r.LocalReport.SetParameters(reportParameters3);
                this.r.LocalReport.SetParameters(reportParameters4);
                this.r.LocalReport.SetParameters(reportParameters5);
                this.r.LocalReport.SetParameters(reportParameters6);
                this.r.LocalReport.SetParameters(reportParameters7);
                this.r.LocalReport.SetParameters(reportParameters8);
                this.r.LocalReport.SetParameters(reportParameters9);
                this.r.LocalReport.DataSources.Add(source);
                this.r.LocalReport.Refresh();
                this.r.RefreshReport();
                this.r.SetDisplayMode(DisplayMode.PrintLayout);
            }
            catch (Exception ex)
            {
                Managementerror.SendError("Errore Stampa Risorse Cantiere: " + ex);
            }

            return this.r;
        }

【问题讨论】:

    标签: c# reporting-services report


    【解决方案1】:

    您是否尝试过从 [Design] 定义报表查看器组件的数据源的数据源,而不是从后面的代码 (.cs) 中定义数据源?其实你可以试试,因为我在使用 RDLC 时总是使用这种方法。

    祝你好运!

    【讨论】:

      猜你喜欢
      • 2021-02-21
      • 1970-01-01
      • 2020-12-07
      • 1970-01-01
      • 1970-01-01
      • 2021-05-08
      • 2023-02-10
      • 1970-01-01
      • 2015-05-09
      相关资源
      最近更新 更多