Dynamic Reporting.ObjectDataSource with DataAccess

2 posts, 0 answers
  1. Jeffrey
    Jeffrey avatar
    1 posts
    Member since:
    Mar 2014

    Posted 01 Dec 2015 Link to this post

    I am building a reporting engine.  The goal is to have a database only driven reporting solution.  I only have one piece remaining to make it work right.

     So I am using reflection to create the report itself off of the database report table and all parameters are dynamically handled on the UI.  The trick is getting the data for the report.  All reports will have a stored procedure to compile the data needed.  Currently I have a report ObjectDataSource being loaded like this:

     public static Telerik.Reporting.ObjectDataSource GetReportDataSource(Dal.Report report, Dictionary<string,object> parameterValues)
                Telerik.Reporting.ObjectDataSource dataSource = new Telerik.Reporting.ObjectDataSource();
                dataSource.DataSource = typeof(ReportLogic);
                dataSource.DataMember = string.Format("GetData{0}", report.Name.Replace(".", ""));
                foreach(KeyValuePair<string,object> parameter in parameterValues)
                    dataSource.Parameters.Add(new Telerik.Reporting.ObjectDataSourceParameter(parameter.Key, parameter.Value.GetType(), parameter.Value));
                return dataSource;

    and each report then has to have a method like this:

     public static IEnumerable<StoredProcedureDomainMethodReturnShapeHere> GetData<ReportNameHere>(<StoredProcedureParametersHere>)
                using (DataContext dataContext = new DataContext())
                    return dataContext.StoredProcedureName(StoredProcedureParameters);

     So the goal is to only have ONE GetData method instead of one per report.  I am not sure if I should use a different object than the ObjectDataSource or how I can make the Stored Procedure call to a dynamically named SP with params.

     Trying to avoid using SQLDataAdapter and Datasets... hoping there is a way to do this with DataAccess dynamically.


  2. Stef
    Stef avatar
    2920 posts

    Posted 02 Dec 2015 Link to this post

    Hi Jeffrey,

    The reporting engine tries to load the data schema (available fields) from the data source component's configuration. Thus the approach to inject the type at a later point is not applicable at design-time.

    My recommendation is to design reports with sample data having the same schema as the actual data. Then at run-time you can make an injection to get the required data, and then bind the retrieved data objects to the report.

    For example:
    //approach one is to modify the report instance
    var report = new MyReport();
    report.DataSource = SetReportDataHere();//there is no need to use a data source component if data is already instantiated
    //set the data source of a nested data item
    var table= report.Items.Find("table1",true)[0] as Telerik.Reporting.Table;
    table.DataSource = SetDataItemDataHere();
    //display the modified report
    var IRS = new InstanceReportSource();
    IRS.ReportDocument = report;

    In case you are using the Reporting HTML5 Viewer and REST service, the above code can be used in a custom resolver's Resolve method.

    Let us know if you need any further help.

    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
  3. DevCraft banner
Back to Top