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

Select command from sqlDataSources comes back empty

1 Answer 64 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Adrian
Top achievements
Rank 1
Adrian asked on 03 May 2018, 03:35 PM

I'm currently doing a little proof of concept, but I'm either failing to understand something or I did something wrong.

Here's the code snippet:

class Program
    {
        static void Main(string[] args)
        {
            Telerik.Reporting.Report report = new Telerik.Reporting.Report();
            string selectCommand = @"SELECT * FROM Test.dbo.TestTable"; //Assume that the query works in SQL
            string connectionString = @"Data Source=.\DEVSQL;Initial Catalog=Test;Integrated Security=True;Persist Security Info=True;";
            Telerik.Reporting.SqlDataSource sqlDataSource = new Telerik.Reporting.SqlDataSource(connectionString, selectCommand);
            report.DataSource = sqlDataSource;
            ExportToPDF(report);
        }


        public static void ExportToPDF(Telerik.Reporting.Report reportToExport)
        {
            ReportProcessor reportProcessor = new ReportProcessor();
            Telerik.Reporting.InstanceReportSource instanceReportSource = new Telerik.Reporting.InstanceReportSource();
            instanceReportSource.ReportDocument = reportToExport;
            RenderingResult result = reportProcessor.RenderReport("PDF", instanceReportSource, null);

            string fileName = result.DocumentName + "." + result.Extension;
            string path = System.IO.Path.GetTempPath();
            string filePath = System.IO.Path.Combine(path, fileName);

            using (System.IO.FileStream fs = new System.IO.FileStream(filePath, System.IO.FileMode.Create))
            {
                fs.Write(result.DocumentBytes, 0, result.DocumentBytes.Length);
            }
        }

    }

After executing this I get an empty PDF, even though the table has several rows.

1 Answer, 1 is accepted

Sort by
0
Katia
Telerik team
answered on 08 May 2018, 08:15 AM
Hello Adrian,

The code seems to be valid. The issue might come from the settings of the report such as:

1. If the data is displayed using a Table/Crosstab/List item, its data source needs to be configured separately. Inner data items do not reuse the data source set for the Report automatically. To access the inner items, you can use Find Method.

2. If report has any filters added check if the filter rule is valid.


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
Adrian
Top achievements
Rank 1
Answers by
Katia
Telerik team
Share this question
or