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 with Razor view engine.

Saving query

  • To retrieve the query text from the query builder use the following code:
    protected void btnGetQuery_Click(object sender, System.EventArgs e)
    {
        QueryBuilder queryBuilder = SessionStore.Current.QueryBuilder;
        PlainTextSQLBuilder sqlBuilder = SessionStore.Current.PlainTextSQLBuilder;
        string plainSQL = queryBuilder.SQL; // unformatted text
        string formattedSQL = sqlBuilder.SQL; // formatted text
    }
  • To retrieve the query text from the text editor, use the following code:
    protected void btnGetQuery_Click(object sender, System.EventArgs e)
    {
        string textSQL2 = SessionStore.Current.ClientSQL;
    }
    If you want to parse the final modifications made to SQL text by the end-user before the query execution, additionaly use the following code:
    try
    {
        SessionStore.Current.QueryBuilder.SQL = SessionStore.Current.ClientSQL;
        // execute the query here
    }
    catch (Exception ex)
    {
        MessageBox.Show(ex.Message, "Parsing error");
    }

Loading query

  • To assign SQL query text to the control use the following code:
    protected void btnSetQuery_Click(object sender, System.EventArgs e)
    {
        SessionStore.Current.QueryBuilder.SQL = "SELECT * FROM ...";
    }
    If you want to do this without reloading a web page, additionaly use the following JavaScript code:
    QB.Web.Application.fullUpdate();
  • To update the SQL text on the client use the following JavaScript code:
    QB.Web.Application.importSQL('Select * From ...');
    QB.Web.Application.refreshSql();

Is this article helpful for you?