2013-08-26 104 views
0

我的要求是在水晶報告中,通過一次單擊生成/打印特定課程的所有學生的標記表。環形印刷水晶報告

當我用For循環話,就說明報告中只有最後一個記錄/頁。

,我的代碼是

私人無效btnGenerate_Click(對象發件人,EventArgs的){

 try 
     { 
      axCrystalActiveXReportViewer1.ReportSource = null; 

      ReportDocument cryRpt = new ReportDocument(); 
      TableLogOnInfos crtableLogoninfos = new TableLogOnInfos(); 
      TableLogOnInfo crtableLogoninfo = new TableLogOnInfo(); 
      ConnectionInfo crConnectionInfo = new ConnectionInfo(); 
      Tables CrTables; 


      crConnectionInfo.ServerName = Configuration.ServerName; 
      crConnectionInfo.DatabaseName = Configuration.DataBaseName; 
      crConnectionInfo.UserID = Configuration.Server_userName; 
      crConnectionInfo.Password = Configuration.Server_password; 



      CrTables = cryRpt.Database.Tables; 
      foreach (CrystalDecisions.CrystalReports.Engine.Table CrTable in CrTables) 
      { 
       crtableLogoninfo = CrTable.LogOnInfo; 
       crtableLogoninfo.ConnectionInfo = crConnectionInfo; 
       CrTable.ApplyLogOnInfo(crtableLogoninfo); 
      } 

      for(int i=0; i<=x; i++) 
      { 
       DataSet ds_ViewTermMarkSheet = new DataSet(); 
       Hashtable htViewTermMarkSheet = new Hashtable(); 

       htViewTermMarkSheet.Add("@Year", txtYear.Text); 
       htViewTermMarkSheet.Add("@Faculty", cboFaculty.Text); 
       htViewTermMarkSheet.Add("@Level", cboClass.Text); 
       htViewTermMarkSheet.Add("@Section", cboSection.Text); 
       htViewTermMarkSheet.Add("@term", cboTerm.Text); 
       htViewTermMarkSheet.Add("@CRN",.ToString()); 

       DbOperations _dbAccess = new DbOperations(); 
       _dbAccess.selectStoredProcedure(ds_ViewTermMarkSheet, "spSelectExamView_Exam_TermWiseMarkSheet", htViewTermMarkSheet, "Marks"); 





      cryRpt.SetDataSource(ds_ViewTermMarkSheet.Tables["Marks"]); 
      } 



       axCrystalActiveXReportViewer1.Refresh(); 


      cryRpt.Close(); 

     } 
     catch (Exception ex) 
     { 
      MessageBox.Show("Mark Sheet generation was not successful.\r" + ex.Message, "Error!"); 
     } 
    } 

我怎麼可以追加多marksheet一次,然後一次打印出來?

回答

0

你要撥打:

cryRpt.SetDataSource(ds_ViewTermMarkSheet.Tables["Marks"]); 

..from出方的for循環

在for循環填充您的數據表與你需要的所有信息。然後從出側循環調用SetDataSource() method.

乾杯

0

你的代碼迴路和數據源多次設置,但會刷新報表只是最後一個。您需要將刷新指數之環andalso打印報告有:

 cryRpt.SetDataSource(ds_ViewTermMarkSheet.Tables["Marks"]); 
     axCrystalActiveXReportViewer1.Refresh(); 
     // print the rpeort 
     } 

來處理這個正確的方法是創建一個報告,該報告顯示有關所有學生的信息。您可以按學生ID或姓名進行分組,並在組後設置新頁面。然後打印這份報告(只有一次)。