2014年4月9日 星期三

RDLC Subreport 讀取

設計RDLC時,通常都是習慣先在BISD(後來改叫SSDT) 建一個報表專案,然後撰寫SQL設計LAYOUT確認報表內容沒問題後再將

讀取MAIN RDLC應該不是問題

 讀取子報表,只需在原來讀取MAIN RDLC的程式碼加入以下

ReportVierwe1.LocalReport.SubreportProcessing += new SubreportProcessingEventHandler(SetSubReportData);

ReportViewer1.LocalReport.Refresh();

void SetSubReportData(object sender, SubreportProcessingEventArgs e)
 {

        int sn = int.Parse(e.Parameters["p_sn"].Values[0]); //子表傳遞參數值
      
        string dsname= string.Empty; //每張子表的datasetname,不同子表要給不同名
      
        DataTable dtsource =new DataTable();//報表資料來源,這里是用datatable回傳型態

        switch(e.ReportPath)  //依子表名稱(rdlc的檔名)來讀取資料
                {
                    case "rdlcname1":
                         dsname = "DS1"; //dataset name in rdlc
                         dt = datasource1; //your sql data table ,code by self
                      break;
                    case "rdlcname1":
                         dsname = "DS2"; //dataset name in rdlc
                         dt = datasource2; //your sql data table ,code by self
                      break;
                 }

           e.DataSources.Add(new ReportDataSource(dsname,dt ));  //設定來源

}

publish error allowDefinition='MachineToApplication'

一個老舊的aspx web form專案,調了一些功能建置成功,但進行部署時顯示以下錯誤。 在應用程式層級之外使用註冊為 allowDefinition='MachineToApplication' 的區段發生錯誤。錯誤的原因可能是虛擬目錄尚未在 IIS 中設定為...