我必须在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;
}
答案 0 :(得分:0)
您是否尝试过从[设计]定义Report Viewer组件数据源的数据源,而不是通过(.cs)后面的代码来定义数据源?实际上,您可以尝试一下,因为在使用RDLC时我总是使用该方法。
祝你好运!