Description

Allows you to enter an SQL query for execution and, if necessary, display the result of the query in a TableGrid component.

Important! To work with this action, you must have knowledge of the SQL query language.


For SQL query you can also use UPDATE, INSERT, DELETE and any other keywords in the syntax.

Let's consider an example of an SQL query to search for records with the desired last name.



Notice in the SQL query the text of {edLastName}, where edLastName is the name of the component (TextBox) in the current form, so the text from this component will be automatically inserted into the SQL query.



Let's consider one more example where we search for clients by their category.



Note in the SQL query for the text of {cbCategory}, where cbCategory is the name of the component (ComboBox) in the current form, so the SQL query will automatically insert the identifier of the category that is selected in the cbCategory component. Thus, will be found clients who belong to the category specified in the cbCategory component.

In all these examples, in the query we added id (e.g.: SELECT lastname, fistname, id FROM...), which is mandatory if we want to be able to edit or delete a record from a table component, in our case with the name GridClients.

If you do not want to see the id value in a TableGrid component, enter a name for this column delete_col

You can use the keyword "$autoinc" to add sequence numbering to the TableGrid component where the query result will be output. For example: SELECT "$autoinc", somefield FROM table

Please note the option: "Select the general database table". In case of complex SQL queries with sub-queries, you need to select the main database table yourself.


In cases when the TableGrid component was populated with data using SQL query, this component will not be automatically updated when data changes in the database table. You can update data in the component as follows: if Form1.TableGrid1.dbSQL <> '' then Form1.TableGrid1.dbSQLExecute;