Page 1 of 1

Remove StiDataSource before report loads

Posted: Wed Feb 16, 2011 8:37 pm
by jay@bplogix.com
In my reports I programmatically add a datasource to an StiDatabase and some StiDataSource's when the report loads. Before I load the report, I want to remove the existing StiDatabase's and StiDataSource's that were saved with the report (I will then re-create them).

I am thinking of naming these programmatically added database and datasources with something like BUILTIN_xyz so I know which ones are "built-in" (anything starting with BUILTIN_) and which ones the user added (all others). I can iterate through the Dictionary.Databases.Items and remove any that start with BUILTIN_ ... but I cannot seem to be able to iterate through the DataSources and find any that were using a database named "BUILTIN_*". How can I tell what database a datasource is connected to?

thx

Remove StiDataSource before report loads

Posted: Fri Feb 18, 2011 6:12 am
by Alex K.
Hello,

You can use the following code:

Code: Select all

StiReport report = new StiReport();
report.Load();
StiDataSourcesCollection sCollect = new StiDataSourcesCollection(new StiDictionary());

foreach (StiDataSource source in report.Dictionary.DataSources)
{
    if (!source.Name.Contains("BUILTIN"))
        sCollect.Add(source);
}
report.Dictionary.DataSources = sCollect;
report.Design();
Thank you.