locked
RDLC DataTable Problem RRS feed

  • Question

  • User-952930563 posted

    Hi everyone,

    I am trying to make a RDLC report.

    This is my code:

    public ActionResult Reports(string ReportType)
    {
     HojapaApplication_dbEntities Entities = new HojapaApplication_dbEntities();

    DataSet1 DataSet1 = new DataSet1();
    DataTable reservatiesTable = DataSet1.Tables["Reservaties"];

    LocalReport localreport = new LocalReport();
    localreport.ReportPath = Server.MapPath("~/Reports/Report_Reservatie.rdlc");

    var entities_data = from c in Entities.Reservaties
                                  select c.Voornaam;

    localreport.DataSources.Add(new ReportDataSource("DataSet1", DataSet1.Tables["Reservaties"]));

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

    I can make an PDF report, but with no data.

    Can anyone tell me what i am doing wrong?

    Thx!!

    Saturday, April 28, 2018 7:27 PM

All replies

  • User-151037245 posted

    Hi Benzo,

    Based on the code you were creating a report data source from the data table Reservaties and you were also pull the data into entities_data. However, there is still no date in the data table Reservaties. You need to fill the data into this data table before you creating the report data source.

    We can use IEnumerable<DataRow>.CopyToDataTable<DataRow>() method to fill the data into data table and more detail about fill data into data table, you can refer the link below:

    Creating a DataTable From a Query (LINQ to DataSet)

    Regards & Fei

    Monday, April 30, 2018 2:46 AM