Creating Reports Programmatically Errors

1 Answer 24 Views
Miscellaneous
Ken
Top achievements
Rank 1
Ken asked on 08 Mar 2025, 03:15 PM

I am trying to create reports programmatically and when I copied the code from the links there are errors.  I am getting the following errors:

           'Report' does not contain a constructor that takes 0 arguments

           'DetailSection' does not contain a constructor that takes 0 arguments

How can the examples be updated?

            https://docs.telerik.com/reporting/embedding-reports/program-the-report-definition/create-report-programmatically

            Report report = new Report();
            string selectCommand = @"SELECT * FROM Sales.Store";
            string connectionString = "Data Source=(local)\\SQLEXPRESS;Initial Catalog=AdventureWorks;Integrated Security=True";
            Telerik.Reporting.SqlDataSource sqlDataSource = new Telerik.Reporting.SqlDataSource(connectionString, selectCommand);
            report.DataSource = sqlDataSource;

 

            https://docs.telerik.com/reporting/embedding-reports/program-the-report-definition/create-sections-programmatically

            DetailSection detail = new DetailSection();
            this.detail.Height = new Telerik.Reporting.Drawing.Unit(3.0, Telerik.Reporting.Drawing.UnitType.Inch);
            this.detail.Name = "detail";
            report.Items.Add((ReportItemBase)detail);

 

Thank you.

1 Answer, 1 is accepted

Sort by
0
Petar
Telerik team
answered on 11 Mar 2025, 04:21 PM

Hello Ken,

The constructor of the Telerik.Reporting.Report class indeed doesn't accept any parameters. You can find its API reference in the following documentation article:

In your example, I suspect you are using Telerik.Reporting.Processing.Report instead, which does not expose a constructor, as it serves a different purpose. The same applies to the DetailSection usage. You can find more information on where the Telerik.Reporting.Processing namespace can be useful in the following documentation article:

To resolve the issue, I recommend updating your code snippet to use the correct namespace as shown below (or simply add the appropriate "using" directive at the beginning of the file):

Telerik.Reporting.Report report = new Telerik.Reporting.Report();
string selectCommand = @"SELECT * FROM Sales.Store";
string connectionString = "Data Source=(local)\\SQLEXPRESS;Initial Catalog=AdventureWorks;Integrated Security=True";
Telerik.Reporting.SqlDataSource sqlDataSource = new Telerik.Reporting.SqlDataSource(connectionString, selectCommand);
report.DataSource = sqlDataSource;
Telerik.Reporting.DetailSection detail = new Telerik.Reporting.DetailSection();
detail.Height = new Telerik.Reporting.Drawing.Unit(3.0, Telerik.Reporting.Drawing.UnitType.Inch);
detail.Name = "detail";
report.Items.Add(detail);

With that said, I will shortly update these two articles to correct the namespace usage, ensuring that no one else encounters this issue in the future.

I hope this helps. Please let me know if you have any further questions on this matter.

Regards,
Petar
Progress Telerik

Enjoyed our products? Share your experience on G2 and receive a $25 Amazon gift card for a limited time!

Tags
Miscellaneous
Asked by
Ken
Top achievements
Rank 1
Answers by
Petar
Telerik team
Share this question
or