How to enumerate all Datasources defined in a report
I know I can get a names datasource with report.GetDataSource() but there seems to be NO way to get a list of all datasources defined in a report.
I'm trying to convert some SRSS reports to Fast-Reports and those reports have multiple seperate queries in them that I added as seperate datasources. Since I also need to have an in( lsit of ID's) that is variable I need to update the SQL. SRSS can take care of this with a paramater that has Multiple value enabled but now I have to do it my self. Since I want some code ot automatically update toe SQL, since all my queries van a part "CLID in (@CLID)" in them I want to replace the "in (@CLID)" with a list of id's like "in (1,2,3,4,5)".
But there seems to be no way to enumerate the Datasources? The reason I go this route is because I want the frx file to be as selfcontained as possible, like the .rdl files in SRSS so I'm trying to build a generic paramater dialog and the fix the SQL queries embedded in the frx before running it.
I guess most people have static reports , an/or use assigning a Dataset (ie a query executed outside the Fast-Report, but still you need to now the name of the dataset, so the code is tightly bound to the frx file, which I want to prevent.
Does amnyone have a good idea or method to get to the Datasources, or should I go another route?
Comments
Hello!
The `Report.Dictionary.DataSources` collection contains items where the `Alias` property specifies the name under which the data source is visible to expressions. An important point to note: this collection only contains items registered via `RegisterData`; tables created via connections (SQL within the .frx file) are located in `Report.Dictionary.Connections[i].Tables`. Example:
foreach (FastReport.Data.DataSourceBase ds in report.Dictionary.DataSources) { if (ds is FastReport.Data.TableDataSource table && !string.IsNullOrEmpty(table.SelectCommand)) { table.SelectCommand = table.SelectCommand.Replace( ‘in (@CLID)’, $‘in ({string.Join(’,‘, ids)})’); } } foreach (FastReport.Data.DataConnectionBase cn in report.Dictionary.Connections) foreach (FastReport.Data.TableDataSource t in cn.Tables) Console.WriteLine($‘{cn.Name}: {t.Alias}’);This will give you a complete list of data sources along with their SQL queries, which you can then edit before calling `Prepare()`