Executing the Commands using TSQLDataSet

From RAD Studio
Jump to: navigation, search

Go Up to Using dbExpress


You can use a unidirectional dataset even if the query or stored procedure it represents does not return any records. Such commands include statements that use Data Definition Language (DDL) or Data Manipulation Language (DML) statements other than SELECT statements. The language used in commands is server-specific, but usually compliant with the SQL-92 standard for the SQL language. The SQL command you execute must be acceptable to the server you are using. Unidirectional datasets neither evaluate the SQL nor execute it, but pass the command to the server for execution.

To execute commands

  1. Choose File > New > Other. The New Items dialog appears.
  2. In the New Items dialog, select Delphi Projects and double-click VCL Forms Application. The Windows Designer displays.
  3. From the dbExpress category of the Tool Palette, drag a TSQLDataSet component to the form.
  4. Specify the command to execute.
  5. Execute the command.
  6. Create and modify server metadata.

To specify the command to execute

  1. Set the CommandType and CommandText properties in the Object Inspector to specify the command for a TSQLDataSet.
  2. Set the SQL property in the Object Inspector to specify the SQL statement to pass to the server for a TSQLQuery .
  3. Set the StoredProcName property in the Object Inspector to specify the name of the stored procedure to execute for a TSQLStoredProc .

To execute the command

  1. If the dataset is an instance of a TSQLDataSet or a TSQLQuery, call the ExecSQL method.
  2. If the dataset is an instance of a TSQLStoredProc, call the ExecProc method.

Tip: If you are executing the query or stored procedure multiple times, it is a good idea to set the Prepared property to True.

To create and modify server metadata

  1. To create tables in a database, use the CREATE TABLE statement.
  2. To create new indexes for those tables, use the CREATE INDEX statement.
  3. To add various metadata objects, use CREATE DOMAIN, CREATE VIEW, CREATE SCHEMA, and CREATE PROCEDURE statements.
  4. To delete any of the above metadata objects, use DROP TABLE, DROP VIEW, DROP DOMAIN, DROP SCHEMA, and DROP PROCEDURE.
  5. To change the structure of a table, use the ALTER TABLE statement.

See Also