我的水晶报告需要两个子报告。主报表显示数据,但子报表不显示。我该如何解决这个问题?
SqlConnection con = new SqlConnection(GlobalClass.constr);
con.Open();
SqlDataAdapter da = new SqlDataAdapter("select company, DocNo, Date, CustomerName, Address, ContactNo, SubTotal, VatType, Total,subtotal2, MainTotal, Discount, GrandTotal FROM CashMemo where docno='"+cashmemono+"'", con);
DataSet ds = new DataSet();
da.Fill(ds, "rptCashMemoReceipt");
SqlDataAdapter da1 = new SqlDataAdapter("select sl1,CylinNo1, Description1, IssueDate, RecvDate, TotalDays, RentAmount FROM CashMemo where docno='"+cashmemono+"'", con);
DataSet ds1 = new DataSet();
da1.Fill(ds1, "subrpt1");
SqlDataAdapter da2 = new SqlDataAdapter("select Slno, CylinNo, Description, Size, Unit, Rate, Amount FROM CashMemo where docno='"+cashmemono+"'", con);
DataSet ds2 = new DataSet();
da2.Fill(ds2, "subrpt2");
rptCashMemoReceipt abc = new rptCashMemoReceipt();
abc.SetDataSource(ds.Tables[0]);
abc.Subreports[0].SetDataSource(ds1.Tables[0]);
abc.Subreports[1].SetDataSource(ds2.Tables[0]);
crystalReportViewer1.ReportSource = abc;
crystalReportViewer1.Refresh();
con.Close();
答案 0 :(得分:1)
您可以使用CrystalDecisions.CrystalReports.Engine.ReportDocument
List<YourType> list_main_report = GetListMain(); // here you implemented sql
List<YourType> list_child_report = GetListChild(); // here you implemented sql
ReportDocument mainReport = new ReportDocument();
ReportDocument childReport = new ReportDocument();
childReport.Load(System.Web.HttpContext.Current.Server.MapPath("~/Reports/") + "child_report.rpt");
childReport.SetDataSource(list_child_report);
mainReport.Load(System.Web.HttpContext.Current.Server.MapPath("~/Reports/") + "main_report.rpt");
mainReport.SetDataSource(list_main_report);
mainReport.Database.Tables[0].SetDataSource(list_main_report);
mainReport.Subreports["child_report.rpt"].Database.Tables[0].SetDataSource(list_child_report);
mainReport.ExportToHttpResponse(ExportFormatType.PortableDocFormat, System.Web.HttpContext.Current.Response, false, "main_report");
childReport.Close();
mainReport.Close();