This is a migrated thread and some comments may be shown as answers.

Providing data via DataTable to deserialized report

1 Answer 191 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Andrew
Top achievements
Rank 1
Andrew asked on 12 Jun 2017, 02:28 PM

I'm working on a proof of concept using Telerik Reporting. The requirements are that the report be loaded from an XML source and provide that report with data via a DataTable (from the System.Data namespace). The problem is that my data isn't showing up in my report. The generated report has table in it and it has the right number of rows but there is no information in any of the rows. Below is a copy of the code I'm using to generate the report:

XmlReaderSettings settings = new XmlReaderSettings
{
    IgnoreWhitespace = true
};
 
using (StringReader sr = new StringReader(template.Layout)) //template.Layout contains a string which is the report XML
using (XmlReader xmlReader = XmlReader.Create(sr, settings))
{
    ReportXmlSerializer xmlSerializer = new ReportXmlSerializer();
 
    TelerikReport reportInstance = (TelerikReport)xmlSerializer.Deserialize(xmlReader);
    DataSet data = BuildDataSet(template, parameters); //Retreives the data from the database in a DataSet
 
    ObjectDataSource dataSource = new ObjectDataSource
    {
        DataSource = data.Tables[0]
    };
 
    reportInstance.DataSource = dataSource;
 
    return reportInstance;
}

The XML for the report (and the value of template.Layout) can be found here. The generated PDF shows 3 rows which is the same number of rows that the DataTable has. That means the DataTable is being read correctly but the data isn't getting parsed correctly for some reason. If I can get this working it would make Telerik the prime candidate for the final version of the software.

1 Answer, 1 is accepted

Sort by
0
Katia
Telerik team
answered on 13 Jun 2017, 03:10 PM
Hello Andrew,

If the report contains a Table/CrossTab item the DataSource property of this item needs to be configured separately. Table cannot reuse the report's data source automatically.

In Report Designer, set the DataSource property of the table to the parent's (report's) data source as demonstrated in Use DataObject as a datasource for nested data items (Table, List, Crosstab, Graph) help article (step 7).

Beware, that if both report and inner table are bound to the same data source and table is inside the Detail section this will cause repeating of the data.

In case, you need the data within the table only you can use Report.Items.Find method to locate the table and assign the data source directly to the table:
var report = new Report1();
Telerik.Reporting.Table table = (Telerik.Reporting.Table)report.Items.Find("table1", true)[0];
table.DataSource = dataSource;

Hope this helps.


Regards,
Katia
Progress Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
General Discussions
Asked by
Andrew
Top achievements
Rank 1
Answers by
Katia
Telerik team
Share this question
or