Guest User

Guest User

  • Tech Writer
  • 2.1k
  • 472.8k

crystal report not working using asp.net mvc in c#

Jul 21 2020 2:54 AM
Hi Team
 
 I need some help, i am uble to get my crystal-report well and need guidance. I have try to use this logic and got nullable exception (SetDatasource). 
  1. // Model  
  2. public class TrainingRegForm  
  3.     {  
  4.         [Key]  
  5.         public Guid? Id { getset; }  
  6.         public string Title { getset; }  
  7.         public string FirstName { getset; }  
  8.         public string LastName { getset; }  
  9.         public string Position { getset; }  
  10.         public string Company { getset; }  
  11.   
  12.         public string StreetAddress { getset; }  
  13.   
  14.         public string StreetAddressLine { getset; }  
  15.   
  16.         public string City { getset; }  
  17.         public string StateProvince { getset; }  
  18.   
  19.         public int ZipCode { getset; }  
  20.   
  21.         public string Email { getset; }  
  22.   
  23.         [Required(ErrorMessage = "This field is required")]  
  24.         [DataType(DataType.PhoneNumber)]  
  25.         public string CellNumber { getset; }  
  26.         public string DietaryRequirement { getset; }  
  27.     }  
  28.   
  29. // Controller  
  30.  public ActionResult Download_XMLReport()  
  31.         {  
  32.             eNtsaRegistration context = new eNtsaRegistration();  
  33.   
  34.             ReportDocument rpt = new ReportDocument();  
  35.             rpt.Load(Path.Combine(Server.MapPath("~/Reports"), "AcademyReports.rpt"));  
  36.             rpt.SetDataSource(from TrainingRegForm in context.TrainingRegs.Take(5) select TrainingRegForm);  // This throws an error each time  i debug it and its annoying and need som help here.
  37.   
  38.             Response.Buffer = false;  
  39.             Response.ClearContent();  
  40.             Response.ClearHeaders();  
  41.   
  42.             rpt.PrintOptions.PaperOrientation = CrystalDecisions.Shared.PaperOrientation.Landscape;  
  43.             rpt.PrintOptions.ApplyPageMargins(new CrystalDecisions.Shared.PageMargins(5, 5, 5, 5));  
  44.             rpt.PrintOptions.PaperSize = CrystalDecisions.Shared.PaperSize.PaperA5;  
  45.   
  46.             Stream stream = rpt.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat);  
  47.             stream.Seek(0, SeekOrigin.Begin);  
  48.   
  49.   
  50.   
  51.   
  52.             return File(stream, "application/xml""eNtsaReportTrainingForm.xml");  
  53.         }  
 
 

Answers (3)