简体   繁体   中英

How to bind a Dataset to CrystalReport in C#

I have a database and I want to use some couple of its tables in my report (Crystal Report), in my code I have

        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 is an instance of a .XDS Dataset

the crystalReportViewer does not show my report

Ive checked this link on stackoverflow but could not get this done

    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();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM