×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Crystal Report to PDF using MVC

Crystal Report to PDF using MVC

Crystal Report to PDF using MVC

(OP)

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

RE: Crystal Report to PDF using MVC

Where do you get the error?

-Dell

DecisionFirst Technologies - Seven-time SAP BusinessObjects Solution Partner of the Year
www.decisionfirst.com

RE: Crystal Report to PDF using MVC

(OP)
It crashes at rd.SetDataSource(i);

RE: Crystal Report to PDF using MVC

(OP)
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;
}
}

RE: Crystal Report to PDF using MVC

You need to pass datatable or dataset as a parameter for SetDataSource.

www.R-Tag.com Viewer and Scheduler for Crystal reports, SSRS and Dynamic Dashboards.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close