Active Query Builder support area

Updating SQL Property when Data Source is removed (.net edition)

Avatar
  • updated
  • Completed
Hi there,

I am using the .net edition. I am taking a number of sql inputs and attempting to synchronise them with the query builder. Each input represents an SQL table.

When an input is removed, I used the following code to remove the input from the Query Builders list of data sources:

foreach (DataSource ds in queryBuilderDataSource.ActiveSubQuery.ActiveUnionSubquery.GetVisibleDataSources())
{
bool found = false;
foreach (ABComponent component in _inputs)
if (component.workingTable.name == ds.NameInQuery)
found = true;
if (found)
continue; queryBuilderDataSource.ActiveSubQuery.ActiveUnionSubquery.FindDatasources(ds.NameInQuery).Remove(ds);
}
}

However, removing the DataSource (if I am doing it correctly) does not seem to update the SQL property of the query builder as the removed data source still appears in the SQL string.

Do I need to issue a further command in order to get the query builder to update it's SQL property when a data source is removed?
Avatar
Hi Chris,

.Remove() method in your code does not destroy anything, but just removes an item from the collection returned by FindDatasource().
To destroy a datasource you should .Dispose() it.
Use the following example for reference:
UnionSubQuery activeUnionSubquery = queryBuilder1.ActiveSubQuery.ActiveUnionSubquery;
DataSourceGroup dataSourceGroup = activeUnionSubquery.FromClause;

List<DataSource> dataSources = new List<DataSource>();
dataSourceGroup.GetDatasources(dataSources);

dataSourceGroup.BeginUpdate();

try
{
    foreach (DataSource dataSource in dataSources)
    {
        if (dataSource.MetadataObject != null &&
            (dataSource.MetadataObject.Name == "Orders" || dataSource.MetadataObject.Name == "Products"))
        {
            dataSource.Dispose();
        }
    }
}
finally
{
    dataSourceGroup.EndUpdate();
    activeUnionSubquery.DesignPane.Invalidate();
}