Remove StiDataSource before report loads

Stimulsoft Reports.NET discussion
Post Reply
jay@bplogix.com
Posts: 251
Joined: Fri Feb 04, 2011 11:46 am
Location: San Diego, CA

Remove StiDataSource before report loads

Post 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
Alex K.
Posts: 6488
Joined: Thu Jul 29, 2010 2:37 am

Remove StiDataSource before report loads

Post 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.
Post Reply