简体   繁体   English

水晶报表子报表没有表异常

[英]Crystal report sub report has not table exception

This may be a common question, but I wasn't able to find a solution after googling. 这可能是一个常见问题,但是在谷歌搜索后我找不到解决方案。 I am using Crystal Report with C# to do reporting. 我正在使用带有C#的Crystal Report进行报告。 I'm having some problems with sub reports: I want to create a Monthly report for Order and OrderDetail. 我在子报表中遇到一些问题:我想为Order和OrderDetail创建一个月报表。 I did it as per the following code, but when run, it throws the Exception "Report has no table" on the sub-report. 我按照以下代码进行操作,但是在运行时,它在子报表上引发异常“ Re​​port has no table”。 Can you help me? 你能帮助我吗?

RpOrder rpt = new RpOrder();
RpOrderDetail sub = new RpOrderDetail();
DataSet dsOrder = new dsOrder();            
DataSet dsOrderDetail = new dsOrderDetail();
dsOrder.Tables.Add(new DataTable());
dsOrder.Tables.Add(new DataTable());
dsOrderDetail.Tables.Add(new DataTable());

foreach(Order nx in listNX )
{
    dsOrder.Tables[0].Rows.Add(
        new object[]{nx.NgayOrder,nx.GetIsNhapString(),nx.NguoiGiaoHang,nx.TongTien}
    );
    foreach(OrderDetail ct in nx.ChiTiets)
    {
        dsOrder.Tables[1].Rows.Add(new object []{
            ct.HangHoa.TenHangHoa,
            ct.HangHoa.MaHang,
            ct.DonGia,
            ct.SoLuong,
            ct.SoLuong * ct.DonGia
        });
    }
}           
rpt.SetDataSource(dsOrder.Tables[0]);
rpt.Subreports[0].SetDataSource(dsOrder.Tables[1]);
crystalReportViewer1.ReportSource = rpt;

Did you try this: 您是否尝试过:

rpt.SetDataSource(dsOrder);

?

If the line above doesn't work check the records in the tables and try to turn the order, set subreport first. 如果上面的行不起作用,请检查表中的记录并尝试更改顺序,请首先设置子报表。

如果在进行更改之前将子报表添加到主报表中,则转到主报表,右键单击子报表,然后单击“重新导入子报表”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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