HomeActive Query Builder - IntroductionQuick Start GuidesQuick Start Guide for .NET WinForms Edition 2.x

1.1. Quick Start Guide for .NET WinForms Edition 2.x

  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();
  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 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 page was: Helpful | Not Helpful