RDLC dynamic table binding

你说的曾经没有我的故事 提交于 2020-01-03 03:20:52

问题


I am new to RDLC reporting, my requirement is simple. I have designed a report and i have set some parameters in that report to populate dynamic data.

Now i have requirement to display table dynamically as well. So what i did:

DataSet InvoiceSummaryDs = new DataSet();
                    DataTable table = new DataTable();
                    table.TableName = "summary";
                    table.Columns.Add( "name", typeof( string ) );
                    table.Rows.Add(Invoice.TotalBooking);
                    table.Rows.Add("£ " + Invoice.BillAmount);
                    table.Rows.Add("£ " + Invoice.BillAmount + "  <br />" + "£ " + Invoice.VatAmount);
                    table.Rows.Add("£ " + Invoice.NetAmount);

                    InvoiceSummaryDs.Tables.Add(table);

                    ReportDataSource rptDataSource = new ReportDataSource("DSPrice", InvoiceSummaryDs.Tables[0]);
                    rv.LocalReport.DataSources.Add(rptDataSource);

                    rv.LocalReport.SetParameters(parms);
                    rv.LocalReport.Refresh();

so there is no issue at server side code but i get error in report: Error 13 The dataset ‘DS_NAME’ refers to the data source “”, which does not exist.

Error 14 The tablix ‘Tablix1’ is in the report body but the report has no dataset. Data regions are not allowed in reports without datasets.

In rdlc file i created a dataset with same name "DSPrice" having no source because i want to populate data from server side dynamically not from here.

I have already seen this example:

http://www.gotreportviewer.com/ Generate RDLC dynamically - Table

in which dynamic table binding is possible thorugh dynamic report creation but i dont want to create dynamic report.

any one guide me what is the solution? any help would be appreciated.


回答1:


Finally, i resolved this issue myself.

Short summary of my requirements: I wanted to bind dataset from code to my RDLC report table.

when i created table inside RDLC report it gave me above mentioned error to provide datasource for table and i got confused why? i need to set it from C# coding.

then i got to know RDLC report cant know if you are going to provide datasource from code unless you create dynamic report through coding and i did'nt want to create dynamic report.

Solution:

1) Create place holder dataset having same name that you want to pass from code 2) that dataset must have same columns and names 3) assign that dataset to table datasource inside your report 4) and use same name columns to pass from coding 5) in this way you wont get that error and you can easily pass dynamic dataset from code.



来源:https://stackoverflow.com/questions/21859215/rdlc-dynamic-table-binding

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!