Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Crystal Report to PDF using MVC

Status
Not open for further replies.

Andec

Programmer
Jun 6, 2013
3
US

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;
}
}
 
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;
}
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top