从DataSet和DataTable生成Crystal Reports

时间:2021-09-23 16:39:50

I need to generate a report in Crystal Reports in an application in which there is only a stand-alone DataSet (not connected to any type of database). Also, I need to generate a report based on the values in DataTable.

我需要在一个应用程序中在Crystal Reports中生成一个报表,其中只有一个独立的DataSet(未连接到任何类型的数据库)。另外,我需要根据DataTable中的值生成报告。

Could you please show me through, I am a newbie. I have a template, but I do not know how to generate a report from a DataTable, nor how to insert in into the templates.

你能告诉我一下,我是新手。我有一个模板,但我不知道如何从DataTable生成报告,也不知道如何插入模板。

1 个解决方案

#1


5  

This article is just for you;

这篇文章只适合你;

Crystal Report with DataSet and DataTable using C#

使用C#的DataSet和DataTable的Crystal Report

  • Binding Our Report to our DataSource

    将我们的报告绑定到DataSource

    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;
            }
        }
    }
    

EDIT: Also you should look this;

编辑:你也应该看看这个;

ADO.NET Datatable as Crystal Report datasource

ADO.NET Datatable作为Crystal Report数据源

How do I populate Crystal Reports, using a DataTable?

如何使用DataTable填充Crystal Reports?

#1


5  

This article is just for you;

这篇文章只适合你;

Crystal Report with DataSet and DataTable using C#

使用C#的DataSet和DataTable的Crystal Report

  • Binding Our Report to our DataSource

    将我们的报告绑定到DataSource

    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;
            }
        }
    }
    

EDIT: Also you should look this;

编辑:你也应该看看这个;

ADO.NET Datatable as Crystal Report datasource

ADO.NET Datatable作为Crystal Report数据源

How do I populate Crystal Reports, using a DataTable?

如何使用DataTable填充Crystal Reports?