RAD Studio VCL Reference
ContentsIndex
PreviousUpNext
TAdoDbxCommand Class

Represents a SQL statement or stored procedure to execute against a data source.

Pascal
TAdoDbxCommand = class(DbCommand, ICloneable);
C++
class TAdoDbxCommand : public DbCommand, public ICloneable;

Borland.Data.AdoDbxClientProvider

Use the TAdoDbxCommand constructor to create a new instance of a TAdoDbxCommand object. The TAdoDbxCommand object is created automatically in your project when you create a TAdoDbxDataAdapter object. The TAdoDbxCommand object provides the means for executing SQL statements and stored procedures.  

TAdoDbxCommand is an implementation of the .NET DbCommand class. 

The CommandType property specifies whether a SQL statement, a table name, or a stored procedure name is being used in the CommandText property.

Depending on the type of SQL statement being executed, you can use one of the following methods:

  • ExecuteReader. Used for Select statements and stored procedures that return a reader or multiple readers. A new TAdoDbxDataReader is returned if ExecuteReader successfully processes the SQL statement. You cannot update data when using a TAdoDbxDataReader object. To update data, use the TAdoDbxDataAdapter object.
  • ExecuteScalar. Similar to ExecuteReader but returns only the first column of the first record as an object and is primarily used to execute SQL to return aggregate values.
  • ExecuteNonQuery. Executes DDL or non-Select DML statements or stored procedures that return no dataset. On successful execution of a DML statement, ExecuteNonQuery returns the number of rows affected in the database.

To execute parameterized SQL, you can specify the CommandText values with parameter markers. The ? character is used as a parameter marker. Currently, there is no support for named parameters. During preparation, the database-specific provider implementation takes care of converting the ? parameter markers to database-specific parameter markers and also takes care of generating the appropriate SQL for calling a stored procedure. 

When executing the same SQL repeatedly, call the Prepare method once and bind parameters. You specify parameters by adding a TAdoDbxParameter instance to the TAdoDbxCommand.Parameters property, which is a TAdoDbxParameterCollection. Preparing a parameterized SQL statement on most databases creates an execution plan on the server that is then used during subsequent execution of the same SQL with different parameter values. 

Once the TAdoDbxCommand is complete, calling Dispose (or Free in Delphi) frees all of the statement resources allocated by the provider. 

 

Copyright(C) 2008 CodeGear(TM). All Rights Reserved.
What do you think about this topic? Send feedback!