C# Winform – Extending solution working for single DataSet to Multiple DataSets for ReportViewer Reports with the help of RDL file -


i had code taken reza aghaei’s solution, had helped me solve problem single dataset using microsofts reportviewer control on winforms.

working part:

calling form:

string sql = "select bk_book_details.id, bk_book_details.book_id, bk_book_details.book_no, bk_book_details.book_name, bk_book_details.edition_id, bk_book_details.condition_id, bk_book_details.publication_year, bk_book_details.price, bk_book_details.purchase_price, bk_book_details.reference_no, bk_book_details.book_status, bk_book_details.purchase_id, bk_book_details.purchase_date bk_book_details"; string reportlocation = path.getdirectoryname(assembly.getexecutingassembly().location) + @"\reports\lms_book_price_invoice.rdl"; var f = new reportform(); f.reportpath = reportlocation; datatable dt = (datatable)dataadapter.current.loaddata(sql, "loaddatatable"); list<datatable> ldt = new list<datatable>(); ldt.add(dt); f.reportdata = new list<datatable>(ldt); f.showdialog(); 

report form:

public list<datatable> reportdata { get; set; } public string reportpath { get; set; }  private void reportform_load(object sender, eventargs e) {     long numberofdatasets = this.reportdata.count();     if (numberofdatasets == 0)         return;      var rds = new microsoft.reporting.winforms.reportdatasource("data", this.reportdata[i]);     this.reportviewer1.localreport.datasources.add(rds);      reportviewer1.localreport.reportpath = this.reportpath;     this.reportviewer1.refreshreport(); } 

which extended take multiple datasets so:

  1. added same sql statement 3 times addition of condition 3 tables added rdl file 3 separate datasets namely: data, data1, data2

code after modification:

calling form:

        string sql = "select bk_book_details.id, bk_book_details.book_id, bk_book_details.book_no, bk_book_details.book_name, bk_book_details.edition_id, bk_book_details.condition_id, bk_book_details.publication_year, bk_book_details.price, bk_book_details.purchase_price, bk_book_details.reference_no, bk_book_details.book_status, bk_book_details.purchase_id, bk_book_details.purchase_date bk_book_details bk_book_details.book_id<=2";         string sql1 = "select bk_book_details.id, bk_book_details.book_id, bk_book_details.book_no, bk_book_details.book_name, bk_book_details.edition_id, bk_book_details.condition_id, bk_book_details.publication_year, bk_book_details.price, bk_book_details.purchase_price, bk_book_details.reference_no, bk_book_details.book_status, bk_book_details.purchase_id, bk_book_details.purchase_date bk_book_details bk_book_details.book_id=4";         string sql2 = "select bk_book_details.id, bk_book_details.book_id, bk_book_details.book_no, bk_book_details.book_name, bk_book_details.edition_id, bk_book_details.condition_id, bk_book_details.publication_year, bk_book_details.price, bk_book_details.purchase_price, bk_book_details.reference_no, bk_book_details.book_status, bk_book_details.purchase_id, bk_book_details.purchase_date bk_book_details bk_book_details.book_id=5";          string reportlocation = path.getdirectoryname(assembly.getexecutingassembly().location) + @"\reports\lms_book_price_invoice_2.rdl";          var f = new reportform();         f.reportpath = reportlocation;         datatable dt = (datatable)dataadapter.current.loaddata(sql, "loaddatatable");         datatable dt1 = (datatable)dataadapter.current.loaddata(sql1, "loaddatatable1");         datatable dt2 = (datatable)dataadapter.current.loaddata(sql2, "loaddatatable2");          list<datatable> ldt = new list<datatable>();         ldt.add(dt);         ldt.add(dt1);         ldt.add(dt2);          f.reportdata = new list<datatable>(ldt);         f.showdialog(); 

report form:

    public list<datatable> reportdata { get; set; }     public string reportpath { get; set; }      private void reportform_load(object sender, eventargs e) {         long numberofdatasets = this.reportdata.count();         if (numberofdatasets == 0)             return;          this.reportviewer1.localreport.datasources.clear();         string datax = "data";         (int = 0 ; < numberofdatasets; i++) {             string dataname = datax;             if (i != 0)                 dataname += convert.tostring(i);             /*for our case dataname used provide dataset name data, data1, data2*/              var rds = new microsoft.reporting.winforms.reportdatasource(dataname, this.reportdata[i]);             this.reportviewer1.localreport.datasources.add(rds);         }         reportviewer1.localreport.reportpath = this.reportpath;         this.reportviewer1.refreshreport();     } 

after this, code continues work single dataset so: enter image description here

however multiple datasets, gives following error: enter image description here

search results:

  1. when looked error, got link don’t know why same error occurs:

can not edit rdl report (2005 defination) in vs 2008

  1. i can see match code in link below solution seems working them:

http://www.dotnetspider.com/resources/28409-reportviewer-with-multiple-dataset-report.aspx

at point have run out of solutions , need help.

edit:

what caused issue in first place?

in order extend problem additional datasets, had copied table in rdl designer. designer seems change <rd:typename> tag <typename>.

at point grateful stackoverflow providing platform me post problems , @rezaaghaei, in multiple occasions has gone mile @ details of problems give solution in times of need.

as addressed in exception, element field has invalid child element typename.

you should use rd:typename instead. example:

<field name="id">   <datafield>id</datafield>   <rd:typename>system.int32</rd:typename> </field> 

the problem second , next data sets, first data set ok.


Comments

Popular posts from this blog

jquery - uncaught exception: DataTables Editor - remote hosting of code not allowed -

java - SSE Emitter : Manage timeouts and complete() -

java - How to resolve error - package com.squareup.okhttp3 doesn't exist? -