0
votes

I have a problem with RDLC Reports. My Report can convert to PDF. I have this code in my controller:

private DataSet GetDataSet()
    {
        MySqlConnection connection = null;
        string connstring = string.Format("Server=myWebsite.com;user id=myUsername;password=myPassword;persist security info=True;database=myDatabase");
        connection = new MySqlConnection(connstring);
        connection.Open();

        string sql = string.Format("Select * FROM Reservaties");
        MySqlDataAdapter ad = new MySqlDataAdapter(sql, connstring);

        DataSet ds = new DataSet();
        ad.Fill(ds);

        return ds;
    }

    public ActionResult Reports(string ReportType)
    {
        LocalReport localreport = new LocalReport();
        localreport.ReportPath = Server.MapPath("~/Reports/Report_Reservatie.rdlc");
        DataSet ds = GetDataSet();
        ReportDataSource rds = new ReportDataSource("Reservaties", ds.Tables[0]);

        localreport.DataSources.Add(rds);
        string reportType = ReportType;
        string mimeType;
        string encoding;
        string fileNameExtension;

        if (reportType == "PDF")
        {
            fileNameExtension = "pdf";
        }
        else
        {
            fileNameExtension = "jpg";
        }
        string[] streams;
        Warning[] warnings;
        byte[] renderedByte;
        renderedByte = localreport.Render(reportType, "", out mimeType, out encoding, out fileNameExtension, out streams, out warnings);
        Response.AddHeader("content-disposition", "attachment:filename + reservaties_report." + fileNameExtension);
        return File(renderedByte, fileNameExtension);
    }

And this is my View:

@model int
@{
ViewBag.Title = "Checkout Complete";
}
<h2>@HojapaApplication.Resources.ResourceNL.CheckoutComplete</h2>
<p>@HojapaApplication.Resources.ResourceNL.ThankForTheOrder: @Model</p>


@Html.ActionLink("Export to PDF", "Reports", new { ReportType = "PDF"}, null)

<p>
    @HojapaApplication.Resources.ResourceNL.MoreShoppingOrNot
    @Html.ActionLink("store","Index", "Home")
</p>

I always get this error:

"An error occurred during local report processing."

Can someone please help me of tell what I am doing wrong?

Thx!!

1
What does the inner exception say? Does the rdlc report have any images?user6277510
This is my Inner Exception: link No, there are no images in the report.user5303319

1 Answers

0
votes

The issue is because your dataset name is incorrect.

Innerexception is -> "Cannot create a data reader for dataset 'DataSet_Reservaties'."

The fundamental mistake here is that in this statement the first parameter should match the name of the dataset -

ReportDataSource rds = new ReportDataSource("Reservaties", ds.Tables[0]);

Once you change the code to the below, it should work.

ReportDataSource rds = new ReportDataSource("DataSet_Reservaties", ds.Tables[0]);