locked
Crystal Report to PDF RRS feed

  • Question

  • User1002795225 posted

    I am trying to send the data from a single record to a Crstal Report that I created and then create a PDF from that report that I can Print.  This is the error message that i get 

    Exception Details: CrystalDecisions.CrystalReports.Engine.DataSourceException: The data source object is invalid.

    Can anyone help me this this? 

    Thank You

    This is the ActionResult that I created.

      public ActionResult ExportReport(int? id)
              {

                InjuryIllness i = db.InjuryIllnesses.Find(id);
                ReportDocument rd = new ReportDocument();
                rd.Load(Path.Combine(Server.MapPath("~/Reports"), "Report_InjuryIllness.rpt"));
               rd.SetDataSource(i);
              
                Response.Buffer = false;
                Response.ClearContent();
                Response.ClearHeaders();
     
                try
                     {
                        Stream stream = rd.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat);
                        stream.Seek(0, SeekOrigin.Begin);
                        return File(stream, "application/pdf", "Report_InjuryIllness.pdf");
                     }
                catch (Exception ex)
                    {
                    throw;
                    }
            }

    Tuesday, November 11, 2014 8:28 AM

All replies

  • User1002795225 posted

    The tutorial I am using creates a list which is not what I want to do but I thought I would try it and see if i could get it to work. I changed my routine to the following and re ran the program. I am now getting the the following error message at the same location DataSet does not support System.Nullable<>. There are no null rows in my table and non of the rows allow for null.
    Do you have any idea how I could get this working? Thank You

    public ActionResult ExportReport(int? id)
    {
    
    // InjuryIllness i = db.InjuryIllnesses.Find(id);
    List<InjuryIllness> i = new List<InjuryIllness>();
    using (wgo_InjuryIllnessEntities dc = new wgo_InjuryIllnessEntities())
    {
    i = dc.InjuryIllnesses.ToList();
    }
    ReportDocument rd = new ReportDocument();
    rd.Load(Path.Combine(Server.MapPath("~/Reports"), "Report_InjuryIllness.rpt"));
    rd.SetDataSource(i);
    
    Response.Buffer = false;
    Response.ClearContent();
    Response.ClearHeaders();
    
    try
    {
    Stream stream = rd.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat);
    stream.Seek(0, SeekOrigin.Begin);
    return File(stream, "application/pdf", "Report_InjuryIllness.pdf");
    }
    catch (Exception ex)
    {
    throw;
    }
    } 

    Monday, November 17, 2014 11:57 AM
  • User-1151753377 posted

    Hi Gabby1,

    Pleae refer to the article that will explain you how to export Crystal Report to PDF.

    http://www.aspsnippets.com/Articles/Create-Generate-Export-PDF-file-using-Crystal-Reports-in-ASPNet-using-C-and-VBNet.aspx

    Regrads & Summer

    Thursday, January 22, 2015 2:07 AM