Display data in crystal report when more than one

2019-09-05 08:42发布

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

2条回答
萌系小妹纸
2楼-- · 2019-09-05 09:14

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();
}
查看更多
聊天终结者
3楼-- · 2019-09-05 09:23

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;
查看更多
登录 后发表回答