首页 > 解决方案 > 在报表数据集中输入数据

问题描述

我必须在 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-servicesreport

解决方案


您是否尝试过从 [Design] 定义 Report Viewer 组件的数据源的数据源,而不是从后面的代码 (.cs) 中定义数据源?您实际上可以尝试一下,因为我在使用 RDLC 时总是使用该方法。

祝你好运!


推荐阅读