gpt4 book ai didi

c# - 从数据集和数据表生成 Crystal 报表

转载 作者:太空宇宙 更新时间:2023-11-03 20:34:39 28 4
gpt4 key购买 nike

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

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

最佳答案

这篇文章就是为你而写的;

Crystal Report with DataSet and DataTable using C#

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

    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?

关于c# - 从数据集和数据表生成 Crystal 报表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5594954/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com