【问题标题】:How to bind a Dataset to CrystalReport in C#如何在 C# 中将数据集绑定到 CrystalReport
【发布时间】:2014-05-04 12:22:58
【问题描述】:

我有一个数据库,我想在我的报告(Crystal Report)中使用它的一些表, 在我的代码中,我有

        testdbDataSet ds = new testdbDataSet();

        testdbDataSetTableAdapters.ProductsTableAdapter productAdapter = new testdbDataSetTableAdapters.ProductsTableAdapter();
        productAdapter.Fill(ds.Products);

        testdbDataSetTableAdapters.RegionTableAdapter regionAdapter = new testdbDataSetTableAdapters.RegionTableAdapter();
        regionAdapter.Fill(ds.Region);  

        ds.AcceptChanges();

        ReportDocument reportDoc = new ReportDocument();
        reportDoc.FileName = "CrystalReport1.rpt";
        reportDoc.SetDataSource(ds);

        crystalReportViewer1.ReportSource = reportDoc;
        crystalReportViewer1.Show();
  • ds 是 .XDS 数据集的一个实例

CrystalReportViewer 不显示我的报告

我检查了 stackoverflow 上的 this 链接,但无法完成此操作

【问题讨论】:

    标签: c# database crystal-reports


    【解决方案1】:
        testdbDataSet ds = new testdbDataSet();
    
        //FETCH FROM ANYWHERE TO a DataTable
        DataTable _DtFrmDBPrd = new DataTable();
        DataTable _DtFrmDBRgn = new DataTable();
    
        _DtFrmDBPrd = GetDataFrmDBPrd();//Filling the DataTable From DB or any where..
        _DtFrmDBRgn = GetDataFrmDBRgn();
    
        ds.Products.Merge(_DtFrmDBPrd);//Both the Data Table should have the same column name and Data Type
        ds.Region.Merge(_DtFrmDBRgn);
    
        ReportDocument reportDoc = new ReportDocument();
        reportDoc.FileName = "CrystalReport1.rpt";
        reportDoc.SetDataSource(ds);
    
        crystalReportViewer1.ReportSource = reportDoc;
        crystalReportViewer1.Show();
    

    【讨论】:

      猜你喜欢
      • 2015-05-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-02-09
      • 2012-02-19
      • 2013-02-06
      相关资源
      最近更新 更多