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

2 posts, 0 answers
  1. Sherwin
    Sherwin avatar
    1 posts
    Member since:
    Dec 2018

    Posted 08 Dec 2018 Link to this post

    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. Silviya
    Admin
    Silviya avatar
    414 posts

    Posted 12 Dec 2018 Link to this post

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