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

How to create a table in Telerik Report with Dynamic columns from SQL Stored procedure

2 Answers 2219 Views
Report Designer (standalone)
This is a migrated thread and some comments may be shown as answers.
Sherwin
Top achievements
Rank 1
Sherwin asked on 08 Dec 2018, 09:12 PM

Good Day,

I would like to as if it is possible to create a table in the report with a dynamic result table from MSSQL Stored Procedure ?

 

Thank you,

Sherwin

2 Answers, 1 is accepted

Sort by
0
Silviya
Telerik team
answered on 12 Dec 2018, 07:17 AM
Hello Sherwin,

If I understood correctly, the requirement is to design report, which SqlDataSource(s) would have different number of data fields based on some condition.

In Telerik Reporting it is assumed that the data schema is known in design time. We recommend the query to always return the same data fields/columns. This way the data fields would be accessible design time and reports could be easily created with our designers, i.e. without additional code.
One workaround I could offer would be to modify the SQL query to always return the same (i.e. all possible) data columns. If a particular data column is not desired, the data records it would contain could be set to some constant value of the corresponding type that is meaningless in the context of the report. In the Report the report item displaying this data field could be hidden when its value is equal to this meaningless constant with Conditional Formatting or Bindings.

If the above approach is not applicable, then it would be necessary to create the report programmatically. I could suggest you to look in the automatically generated InitializeComponent method of the Report class when Visual Studio designer is used. All code generating the Report definition is there, and could be an excellent guide to creating/modifying a Telerik Reporting Report programmatically.

For your convenience there is a sample project attached that dynamically modifies a Table based on the fields of the provided CsvDataSource. The two CsvDataSources mimic two possible states of an SqlDataSource fed by a SQL query with different data fields based on some condition.
I could suggest you to change the data source by assigning it either the value returned by GetFirstDataSource, or by GetSecondDataSource method to view the effect on the generated Table. Note that in design time the Table has a single column (that is supposed to be always present), and the rest of the columns are generated dynamically by the FormatTableBasedOnDataSource method.

Regards,
Silviya
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
0
Channah Miriam
Top achievements
Rank 1
answered on 10 Jun 2020, 10:26 AM
Thanks, this was really helpful!
Tags
Report Designer (standalone)
Asked by
Sherwin
Top achievements
Rank 1
Answers by
Silviya
Telerik team
Channah Miriam
Top achievements
Rank 1
Share this question
or