Active Query Builder support area

How to get and set SQL query text in ASP.NET Edition?

Last modified:


This article provides samples of saving and loading the queries between work sessions and describes how to handle SQL query text updates programmatically using Active Query Builder ASP.NET Edition. 

Saving query

  • To retrieve the query text from the query builder, use the following code:

        QueryBuilder queryBuilder = QueryBuilderStore.Get();
        string plainSQL = queryBuilder.SQL; // unformatted text
        string formattedSQL = sqlBuilder.FormattedSQL; // formatted text
  • To retrieve the query text from the text editor, use the following JavaScript code:

    var qb = AQB.Web.QueryBuilder;
    var text = qb.EditorComponent.getSql();
    qb.setSql(text, function(data){ console.log(data)});
    // do something in the callback function when server returns the result
  • To save the query along with the layout of objects on Design Pane, use the queryBuilder.LayoutSQL property:

        QueryBuilder queryBuilder = QueryBuilderStore.Get();
    string xmlSQLwithLayout = queryBuilder.LayoutSQL;

Loading query

  • To assign SQL query text to the query builder use the following code:

        QueryBuilder queryBuilder = SessionStore.GetQueryBuilder();
    queryBuilder.SQL = "SELECT * FROM ...";

    If you want to do this without reloading a web page, additionally use the following JavaScript code:

    AQB.Web.QueryBuilder.update();
  • To update the SQL text on the client use the following JavaScript code:

    AQB.Web.QueryBuilder.setSQL('Select * From ...'); // set custom SQL text
    // or AQB.Web.QueryBuilder.refreshSql(); // text from the SQL text editor typed by the user
  • To load the query along with the layout of objects on Design Pane, use the same queryBuilder.LayoutSQL property:

        QueryBuilder queryBuilder = QueryBuilderStore.Get();
    queryBuilder.LayoutSQL = xmlSQLwithLayout; // XML string

Is this article helpful for you?