Click here to Skip to main content
15,921,210 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
hi to all,
Good After Noon
this is Hem Raj Thakur and I want to add sub report in a crystal report Header part in all report(windows application C#.net).
I am adding a sub report and type a code like:---
------------------------------------------------------------
C#
private void Area_Report_Load(object sender, EventArgs e)
{
   try
   {
      string str = "select a.areaname as Area_Name, b.cname as Country,c.sname as State,d.dname as District from tbl_area a inner join tbl_country b on a.cid = b.cid inner join tbl_district d on a.did = d.did and b.cid = d.cid inner join tbl_state c on a.sid =c.sid and a.cid = c.cid and d.sid =c.sid";
      SqlDataAdapter da = new SqlDataAdapter(str, con);
      DataSet_Area ds = new DataSet_Area();
      da.Fill(ds);

      string str1 = "select depid,depname,loc from tbl_Department";
      SqlDataAdapter da1 = new SqlDataAdapter(str1, con);
      DataSet_Dept ds1 = new DataSet_Dept();
      da.Fill(ds1);

      CrystalReport_Area report = new CrystalReport_Area();
      report.SetDataSource(ds.Tables[1]);
      crystalReportViewer1.ReportSource = report;
      //crystalReportViewer1.Refresh();
      //-----------------------Add Sub Report---------------------
      ReportDocument subreport = new ReportDocument();
      //Error Sub Report is not loading please help?
      subreport.Load("CrystalReport_Dept.rpt"); //--Sub Report is not Load
      //subreport.Load(Server.MapPath("CrystalReport6.rpt"));
      subreport.Database.Tables[0].SetDataSource(ds1.Tables[1]);
      report.Subreports["CrystalReport_Dept.rpt"].SetDataSource(ds1.Tables[1]);
   }
   catch (Exception)
   { }
}

-------------------------------------------------------
Please help Me. It is Urgent..........

thanks in advance.
regards
Hem Raj Thakur
Posted
Updated 9-Dec-13 21:05pm
v3
Comments
thatraja 10-Dec-13 3:06am    
what's the problem? any error?
Hem Raj Thakur 10-Dec-13 4:00am    
sir my sub report is not load. it means only area report is display in this code and the department report is not displaying. please help me.
thatraja 10-Dec-13 8:44am    
Did you check my answer?
thatraja 11-Dec-13 3:58am    
Again check my updated answer. And don't delete your comments.
Nelek 10-Dec-13 3:07am    
I am sorry if you need it fast, but saying "it's urgent" is not going to make any difference. People here help for free in their spare time, that means it will be answered as soon as someone knowing the answer comes to this question. If that is not enough... nobody can do more

Why not add the subreport on the design time of the main report?
 
Share this answer
 
Just spotted the issue. You're doing wrong order. Move the below line to last(should be ending line of try block.
C#
crystalReportViewer1.ReportSource = report;

You should assign the Reportsource to crystalReportViewer after adding the subreport things.

EDIT
--------------
Quote:
yes sir i check but error is display like "Load report failed." after this line error jumps on catch block the line is:----- subreport.Load("CrystalReport_Dept.rpt");
Check this Tip/Trick
Crystal Reports: Fix for "Load report failed" error.[^]
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900