Getting started with AQB.NET 2 WinForms Edition
Last modified:
-
Place the QueryBuilder component on the form.
using ActiveDatabaseSoftware.ActiveQueryBuilder; ... QueryBuilder queryBuilder1 = new QueryBuilder();
-
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. -
Link the components above to the QueryBuilder by setting MetadataProvider and SyntaxProvider properties
queryBuilder1.MetadataProvider = metadataProvider; queryBuilder1.SyntaxProvider = syntaxProvider;
-
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;
-
Add the TextBox or any other text editing component to a form.
-
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;
- Call the following method to activate Active Query Builder's database schema tree:
queryBuilder1.InitializeDatabaseSchemaTree();
-
That's all! Now you can run your application.