Select command from sqlDataSources comes back empty

2 posts, 0 answers
  1. Adrian
    Adrian avatar
    2 posts
    Member since:
    May 2018

    Posted 03 May Link to this post

    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.

  2. Katia
    Admin
    Katia avatar
    693 posts

    Posted 08 May Link to this post

    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
Back to Top