2011-04-08 108 views
0

我需要在只有獨立數據集(未連接到任何類型的數據庫)的應用程序中的Crystal Reports中生成報表。另外,我需要根據DataTable中的值生成報告。從數據集和數據表中生成水晶報表

您能否請我看看,我是一個新手。我有一個模板,但我不知道如何從DataTable生成報告,也不知道如何插入到模板中。

回答

5

本文僅供您參考;

Crystal Report with DataSet and DataTable using C#

  • 結合我們的報告給我們的數據源

    using System; 
    using System.Collections.Generic; 
    using System.ComponentModel; 
    using System.Data; 
    using System.Drawing; 
    using System.Text; 
    using System.Windows.Forms; 
    using System.Data.OracleClient; 
    using System.IO; 
    
    namespace CrystalReportWithOracle 
    { 
        public partial class frmMain : Form 
        { 
         public frmMain() 
         { 
          InitializeComponent(); 
         } 
    
         private void frmMain_Load(object sender, EventArgs e) 
         { 
          my_rpt objRpt; 
          // Creating object of our report. 
          objRpt = new my_rpt(); 
    
          String ConnStr = "SERVER=mydb;USER ID=user1;PWD=user1"; 
    
          OracleConnection myConnection = new OracleConnection(ConnStr); 
    
          String Query1 = "select a.PROJECT_ID,a.PROJECT_NAME,b.GROUP_NAME from 
          tbl_project a,tbl_project_group b where a.group_code= b.group_code"; 
    
          OracleDataAdapter adapter = new OracleDataAdapter(Query1, ConnStr); 
    
          DataSet Ds = new DataSet(); 
    
          // here my_dt is the name of the DataTable which we 
          // created in the designer view. 
          adapter.Fill(Ds, "my_dt"); 
    
          if (Ds.Tables[0].Rows.Count == 0) 
          { 
           MessageBox.Show("No data Found", "CrystalReportWithOracle"); 
           return; 
          } 
    
          // Setting data source of our report object 
          objRpt.SetDataSource(Ds); 
    
          CrystalDecisions.CrystalReports.Engine.TextObject root; 
          root = (CrystalDecisions.CrystalReports.Engine.TextObject) 
           objRpt.ReportDefinition.ReportObjects["txt_header"]; 
          root.Text = "Sample Report By Using Data Table!!"; 
    
          // Binding the crystalReportViewer with our report object. 
          crystalReportViewer1.ReportSource = objRpt; 
         } 
        } 
    } 
    

編輯:你也應該看看這一點;

ADO.NET Datatable as Crystal Report datasource

How do I populate Crystal Reports, using a DataTable?

+0

的事情是我的報告是一個模板,它被添加到項目的文件,我需要加載的是,我沒有任何水晶報表實際上瀏覽器。我該怎麼辦? – 2011-04-08 12:39:35

+0

@Faulty我認爲你絕對讀這篇文章http://www.c-sharpcorner.com/uploadfile/mahesh/crystalreportsintroduction11082005014959am/crystalreportsintroduction.aspx – 2011-04-08 13:02:32