Andiana
Andiana

Reputation: 1952

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. I'm having some problems with sub reports: I want to create a Monthly report for Order and OrderDetail. I did it as per the following code, but when run, it throws the Exception "Report has no table" on the sub-report. 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;

Upvotes: 0

Views: 829

Answers (2)

Lan
Lan

Reputation: 1346

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.

Upvotes: 1

teej
teej

Reputation: 165

If the sub report was added to the main report before changes were made then go to the main report, right click on the sub report and "Re-import Subreport"

Upvotes: 0

Related Questions