EPUB | CHM | PDF

TMySQLQuery.Properties.Params

Top Previous Next

Contains the parameters for a query's SQL statement.

Syntax:

property Params[Index: Word]TParams;

Description:

Access Params at runtime to view and set parameter names, values, and data types dynamically (at design time use the collection editor for the Params property to set parameter information). Params is a zero-based array of TParams parameter records. Index specifies the array element to access.

note An easier way to set and retrieve parameter values when the name of each parameter is known is to call ParamByNameParamByName cannot, however, be used to change a parameter's data type or name.

Parameters used in SELECT statements cannot be NULL, but they can be NULL for UPDATE and INSERT statements.

Example:

The following code runs an insert query to add a record for Lichtenstein into the country table.

MySQLQuery2.SQL.Clear;
MySQLQuery2.SQL.Add('INSERT INTO COUNTRY (NAME, CAPITAL, POPULATION)');
MySQLQuery2.SQL.Add('VALUES (:Name, :Capital, :Population)');
MySQLQuery2.Params[0].AsString := 'Lichtenstein';
MySQLQuery2.Params[1].AsString := 'Vaduz';
MySQLQuery2.Params[2].AsInteger := 420000;
MySQLQuery2.ExecSQL;