Active Query Builder support area

Getting started with AQB.NET 2 WinForms Edition

Last modified:


  1. Place the QueryBuilder component on the form.
    using ActiveDatabaseSoftware.ActiveQueryBuilder;
    ...
    QueryBuilder queryBuilder1 = new QueryBuilder();
  2. Place required metadata and syntax provider components on the form. Define a proper database connection object for the metadata provider.
    OleDbConnection connection = new OleDbConnection();
    connection.ConnectionString = "<your connection string here>";
    OLEDBMetadataProvider metadataProvider = new OLEDBMetadataProvider();
    metadataProvider.Connection = connection;
    GenericSyntaxProvider syntaxProvider = new GenericSyntaxProvider();
    Connection string examples can be found here.
  3. Link the components above to the QueryBuilder by setting MetadataProvider and SyntaxProvider properties
    queryBuilder1.MetadataProvider = metadataProvider;
    queryBuilder1.SyntaxProvider = syntaxProvider;
  4. Place an SQLBuilder component on the form to get SQL code generated by the QueryBuilder component with formatting. Link it to the QueryBuilder object by setting the QueryBuilder property.
    PlainTextSQLBuilder sqlBuilder = new PlainTextSQLBuilder();
    sqlBuilder.QueryBuilder = queryBuilder1;
  5. Add the TextBox or any other text editing component to a form.
  6. Now you should establish a connection between SQLBuilder and the TextBox components.
    Enter the following code to the Validate event of TextBox component:
    private void textBox1_Validating(object sender, System.ComponentModel.CancelEventArgs e)
    {
        try
        {
            // Update the query builder with manually edited query text:
            queryBuilder.SQL = textBox1.Text;
        }
        catch (SQLParsingException ex)
        {
            e.Cancel = true;
            // Set caret to error position
            textBox1.SelectionStart = ex.ErrorPos.pos;
            // Report error
            MessageBox.Show(ex.Message, "Parsing error");
        }
    }
    Enter the following code to SQLUpdated event of SQLBuilder component:
    textBox1.Text = sqlBuilder.SQL;
  7. Call the following method to activate Active Query Builder's database schema tree:
    queryBuilder1.InitializeDatabaseSchemaTree();
  8. That's all! Now you can run your application.

This article was helpful for 1 person. Is this article helpful for you?