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

Accessing report datasources from code

1 Answer 343 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
JS
Top achievements
Rank 1
JS asked on 24 Jul 2012, 07:02 AM
Hi,

How do I get references to report datasources from code? I know I can access them inside the report class but I need to get them outside the report class (without knowing/typecasting to that certain class type), like if I have reference to some report just as general report class and it containts openAccessDataSource1, how do I get reference to it or to all the datasources similar to this way in the link (which does not work for them):

http://www.telerik.com/community/forums/reporting/telerik-reporting/loop-through-all-controls.aspx#1871947

1 Answer, 1 is accepted

Sort by
0
Accepted
Steve
Telerik team
answered on 26 Jul 2012, 01:17 PM
Hi JS,

You can get the datasource component directly from the DataSource property of any Data Item e.g.: report.DataSource where report is your report object instance. You can get any nested data items in the report like this (this is sample code snippet):

if (reportItemBase is Report)
        {
            var report = (Report)reportItemBase;
     
            if (report.DataSource is OpenAccessDataSource)
            {
                var openAccessDataSource1 = (OpenAccessDataSource)report.DataSource;
                //perform additional operations on the datasource object if needed
            }
            foreach (var parameter in report.ReportParameters)
            {
                if (parameter.AvailableValues.DataSource is OpenAccessDataSource)
                {
                    var openAccessDataSource1 = (OpenAccessDataSource)parameter.AvailableValues.DataSource;
                    //perform additional operations on the datasource object if needed
                }
            }
        }
     
        foreach (var item in reportItemBase.Items)
        {
            //valid for Crosstab, Table and List data items
            if (item is Table)
            {
                var table = (Table)item;
                if (table.DataSource is OpenAccessDataSource)
                {
                    var openAccessDataSource1 = (OpenAccessDataSource)table.DataSource;
                    //perform additional operations on the datasource object if needed
                    continue;
                }
            }
           //any other data items go here
         ......
        }
   }
}

Regards,
Steve
the Telerik team

BLOGGERS WANTED! Write a review about Telerik Reporting or the new Report Designer, post it on your blog and get a complimentary license for Telerik Reporting. We’ll even promote your blog and help bring you a few fresh readers. Yes, it’s that simple. And it’s free. Get started today >

Tags
General Discussions
Asked by
JS
Top achievements
Rank 1
Answers by
Steve
Telerik team
Share this question
or