[英]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.