[英]Creating an rdlc report with multiple tables (one-to-many relationship)
所以,我是rdlc的新手(并且实际上报道了)。 我有一个与另一个表有一对多关系的表,我试图在rdlc报告中将它们表示为每个项目的多个表。
注意:这些表最初是使用Entity Framework代码优先创建的 。
这是两个表(和父表) :
现在,通常如果我只有[Quotation]
和一些[QuotationItem]
,我只需要在报告顶部的[Quotation]
添加信息,并且每个[QuotationItem]
将在表格内的一行(Tablix)。
问题是 :每个[QuotationItem]
也有许多 [QuotationItemQuantity]
(目前是三个),它们也需要表示。
所以,我的报告应该是这样的:
但我仍然坚持如何为每个项目(QuotationItem)显示多个表(或列表和表)。 我在列表中尝试了嵌套的表和表,但这似乎不被允许(我得到一个“详细信息成员只能包含静态内部成员”错误)。
我读到了关于子报告的内容,我认为这可能是要走的路,但我不确定如何在这种情况下使用子报告,或者这是否是正确的方法。
注意:如上所述,每个QuotationItem
当前有3个数量,但将来可能会更改,因此如果列可以是动态的,那么这将是很好的,但是,此时这不是必需的。
有什么建议?
好吧,我希望(现在仍然)能够获得一个更优雅的解决方案, 而不是这个丑陋的解决方案(我现在必须使用它),但无论如何它都应该做到了。
我发布它,因为它可能会帮助有类似问题的人。 这是我做的:
为了传递实际数据,我将使用与设计数据相同的结构填充DataTable ,然后使用以下内容将其传递给报表:
private void Form_Load(object sender, EventArgs e) { rptViewerMain.LocalReport.ReportEmbeddedResource = "MyProjectName.QuotationReport.rdlc"; rptViewerMain.LocalReport.EnableExternalImages = true; if (QuotationInfo !=null && QuotationItems != null) { SetupReport(); } this.rptViewerMain.RefreshReport(); } private void SetupReport() { var param1 = new ReportParameter("MyFirstParameter", SomeValue); var param2 = new ReportParameter("MySecondParameter", SomeOtherValue); // etc // Pass Parameters rptViewerMain.LocalReport.SetParameters(new[] { param1, param2, "etc" }); // Prepare the DataTable and add the values to it DataTable dt = new MyDummyDataset.MyDesignedDataTable().Clone(); foreach (var qItem in QuotationItems) { dt.Rows.Add(qItem.ItemNumber, qItem.ItemDescription, "and", "so", "many", "more", "values"); } // Pass the DataTable to the report as the data source replacing the dummy DataSet rptViewerMain.LocalReport.DataSources.Add(new ReportDataSource("MyDummyDataset", dt)); }
注意:某些字段/变量名称在问题和答案中都已更改,但这个想法保持不变。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.