Click here to Skip to main content
15,868,122 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to send the data from a single record to a Crystal Report that I created and then create a PDF from that report that I can Print. This is the error message that I get. I am using MVC.

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;
}
}
Posted

1 solution

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

C#
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;
}
}</injuryillness></injuryillness>
 
Share this answer
 

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