简体   繁体   中英

Display data in crystal report when more than one table in DataSet

I am using Crystal Report with VS 10,

I have added DataSet.

Now if There's only One Table in DataSet then data is being displayed, while if i add Two Tables with Link, then Data is not being display.

And i am taking fields from this table of DataSet(XSD).

How to overcome this problem.

Thanks In Advance. Khilen

You need to bind the DataTable(s) that you intend to use instead of binding the entire DataSet. This SO answer shows a very good example: https://stackoverflow.com/a/8341474/283895

(Code copied from that article)

ReportDocument rpt = new ReportDocument();
rpt.load();
rpt.Database.Tables[0].SetDataSource(ds.Tables[0]); 
this.crystalReportViewer1.ReportSource = rpt;

What I'm used to do is ;

  1. add 2 dataset to crstal report.
  2. Below code for blinding 2 dataset into same report.

C#

  public partial class Default2 : System.Web.UI.Page
{
    SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrings["MyCtr1"].ConnectionString);
    SqlConnection cn1 = new SqlConnection(ConfigurationManager.ConnectionStrings["MyCtr2"].ConnectionString);
    ReportDocument rdoc = new ReportDocument();
    DataTable ds = new DataTable();
    DataTable ds1 = new DataTable();
    protected void Page_Load(object sender, EventArgs e)
    {

        if (!IsPostBack)
        {

            loadreport();
            }

  private void loadreport()
{
{              
        cn.Open();
        SqlDataAdapter da = new SqlDataAdapter("select *  from [MyTable1] where (Number LIKE '" + DropDownList1.Text + "') ", cn);
       da.Fill(ds);
       cn.Close();
{
{
       cn1.Open();
       SqlDataAdapter da1 = new SqlDataAdapter("select *  from [MyTable2] where (No LIKE '" + DropDownList1.Text + "') ", cn1);
            //DataTable ds1 = new DataTable();
        da1.Fill(ds1);
     cn1.Close();
}
    rdoc.Database.Tables[0].SetDataSource(ds);
    rdoc.Database.Tables[1].SetDataSource(ds1);

    InvoiceReport.ReportSource = rdoc;
    InvoiceReport.DataBind();
}

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