Dynamically list each data source and it's underlying query

Stimulsoft Reports.WEB discussion
Post Reply
ianwelsh
Posts: 19
Joined: Mon Sep 25, 2017 1:54 pm

Dynamically list each data source and it's underlying query

Post by ianwelsh »

I would like to add a text box to the end of all my reports that dynamically displays all the underlying data sources involved in the report, and each one's underlying sql query.

Can you suggest a way to do this dynamically?

I would like it to be dynamic because I'm lazy and have a LOT of reports to which I'd like to add this, not to mention that I dont want to have to update any static text if the report is changed slightly over time.
Attachments
2018-04-11_9-57-06.png
2018-04-11_9-57-06.png (76.01 KiB) Viewed 3469 times
Edward
Posts: 2913
Joined: Fri Jun 09, 2006 4:02 am

Re: Dynamically list each data source and it's underlying qu

Post by Edward »

Hi Ian,

Please add the following method to the 'Code Tab' as per the attached report template:

Code: Select all

		public string GetDataSourcesNames()
		{
			var result = "";
			foreach (var d in Dictionary.DataSources)
			{
				if (d is Stimulsoft.Report.Dictionary.StiSqlSource)
				{
					result += "Sql Source - " + (d as Stimulsoft.Report.Dictionary.StiSqlSource).Name + Environment.NewLine;
				}				
				else if (d is Stimulsoft.Report.Dictionary.StiDataTableSource)
				{
					result += "DataTable Source - " + (d as Stimulsoft.Report.Dictionary.StiDataTableSource).Name + Environment.NewLine;
				}								
			}
			return result;
		}
Then you will be able to use that custom function in the following way in the report:

{GetDataSourcesNames()}

In order to get around easier with the classes and to investigate the properties you need to use, there is an easy trick on how to do that in Visual Studio.
First, you will need to save your report from the designer as 'c# - class' with help of File -> 'Save As' command in the designer. Then just add this class to an empty project in VS - so you will be able to use the Intellisense to navigate through the required for your task classes.

Thank you,
Edward
Attachments
CodeTab-GetDataSourcesNames.mrt
(16.38 KiB) Downloaded 195 times
ianwelsh
Posts: 19
Joined: Mon Sep 25, 2017 1:54 pm

Re: Dynamically list each data source and it's underlying qu

Post by ianwelsh »

Thank you much!
Lech Kulikowski
Posts: 6239
Joined: Tue Mar 20, 2018 5:34 am

Re: Dynamically list each data source and it's underlying qu

Post by Lech Kulikowski »

Hello

We are always glad to help you!
Please let us know if you need any additional help.

Thank you.
Post Reply