Denis Morgan

Denis Morgan

  • NA
  • 72
  • 22.5k

Creating subreport in cystal report

Dec 14 2020 4:18 AM
I have created this model object in C# and want to create a report with sub report and don't know how to link the 2; Here is my model
  1. public class LabReport  
  2. {  
  3. public int ref_id{get;set;}  
  4. public String t_name { getset; }  
  5. public IList<LabSubReport> result { getset; }//this where i need subreport  
  6. }  
  7. public class LabSubReport  
  8. {  
  9. public int ref_id { getset; }//foreign key from Above model  
  10. public String l_test { getset; }  
  11. public String t_value { getset; }  
  12. }  
and this is how Have populated my model
  1. IList<LabReport> report=report=new List<LabReport>();  
  2. IList<LabRequestEntity> empo =//dao to fetch data  
  3. int count = 1;  
  4. foreach (LabRequestEntity e in empo)  
  5. {  
  6.     IList<LabTestNoteEntity>  notes=e.test_note;//entity relation ship here  
  7.     IList<LabSubReport> sublist=new List<LabSubReport>();  
  8.       
  9.      
  10.     foreach(LabTestNoteEntity p in notes)  
  11.     {  
  12.        var sub=new LabSubReport()  
  13.        {  
  14.           l_test=p.test,  
  15.           t_value=p.result  
  16.        };  
  17.         sublist.Add(sub);  
  18.     }  
  19.   
  20.     var rpt = new LabReport()  
  21.     {  
  22.         ref_id = "" + count,  
  23.         t_name=e.lab_test.t_name,  
  24.         result=sublist  
  25.           
  26.     };  
  27.     count++;  
  28.     report.Add(rpt);  
  29.   
  30. }  
And I would wish my report to look this way. Where its highlighted with blue is where i need the sub-report to be
 
 
 
I have tried this
  1. ReportDocument cryRpt = new ReportDocument();  
  2. cryRpt.Load("C:/MainReport.rpt");  
  3. cryRpt.DataSourceConnections.Clear();  
  4. cryRpt.SetDataSource(report);  
  5. cryRpt.Subreports[0].DataSourceConnections.Clear();  
  6. cryRpt.Subreports[0].SetDataSource(report.select(x=>x.result));  
and getting this error
 
Column 'ref_id' does not belong to table LabSubReport 

Answers (1)