从数据集和数据表生成 Crystal 报表

Generating Crystal Reports from DataSets and DataTables(从数据集和数据表生成 Crystal 报表)
本文介绍了从数据集和数据表生成 Crystal 报表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

你能帮我看看吗,我是新手.我有一个模板,但我不知道如何从 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.

推荐答案

这篇文章只适合你;

Crystal Report 与 DataSet 和 DataTable 使用 C#

  • 将我们的报告绑定到我们的数据源

  • Binding Our Report to our 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;
        }
    }
}

你也应该看看这个;

ADO.NET数据表作为 Crystal Report 数据源

怎么做我使用 DataTable 填充 Crystal Reports?

这篇关于从数据集和数据表生成 Crystal 报表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

DispatcherQueue null when trying to update Ui property in ViewModel(尝试更新ViewModel中的Ui属性时DispatcherQueue为空)
Drawing over all windows on multiple monitors(在多个监视器上绘制所有窗口)
Programmatically show the desktop(以编程方式显示桌面)
c# Generic Setlt;Tgt; implementation to access objects by type(按类型访问对象的C#泛型集实现)
InvalidOperationException When using Context Injection in ASP.Net Core(在ASP.NET核心中使用上下文注入时发生InvalidOperationException)
LINQ many-to-many relationship, how to write a correct WHERE clause?(LINQ多对多关系,如何写一个正确的WHERE子句?)