2012-05-10 9 views
0

私はmicrosoftreportviewerを使用しているWindowsフォームを持っており、これを1つのデータセットで正常に実行できます。テーブルtable1、table2、table3があるとします。これらのすべてをReportViewerにプログラムでReportViewer_Loadに追加するにはどうすればよいですか?ありがとう!複数のテーブルを使用するmicrosoftreportviewer

注:これらのすべてのテーブルは異なる列

答えて

0

を持っているあなたは、一度自分の名前でいずれかを選択し、報告することをバインドしますか?それがあなたが探しているものなら、以下のコードはあなたを助けるかもしれません:

private DataTable GetData(string tableName) 
    { 
     DataSet ds = new DataSet(); 
     string query = "Select * from something"; 
     OdbcDataAdapter da = new OdbcDataAdapter(query, conn); 
     da.Fill(ds); 
     DataTable dt = ds.Tables[tableName]; 
     return dt; 
    } 
//You can fill the dataset once and then just get the table by table name. No necessary that you have to fill the dataset every time to get tables 

    private void RunReportViewer() 
    { 
     this.ReportViewer1.Reset(); 
     this.ReportViewer1.LocalReport.ReportPath = Server.MapPath("Report.rdlc"); 
     ReportDataSource rds = new ReportDataSource("#_your_table_Name", GetData()); 
     this.ReportViewer1.LocalReport.DataSources.Clear(); 
     this.ReportViewer1.LocalReport.DataSources.Add(rds); 
     this.ReportViewer1.DataBind(); 
     this.ReportViewer1.LocalReport.Refresh(); 
    } 
関連する問題