RAD Studio VCL Reference
ContentsIndex
PreviousUpNext
TClientDataSet.CommandText Property

Specifies an SQL command to be executed by the database server.

Pascal
property CommandText: WideString;
C++
__property BSTR CommandText;

CommandText specifies what data the client dataset wants to receive from its (internal or external) provider. It is either  

An SQL statement (query) for the database server to execute. 

The name of a table or stored procedure. 

If the client dataset uses an internal provider, CommandText is required. On TSQLClientDataSet, the CommandType property indicates whether it represents a query, table name, or stored procedure name.  

If the client dataset uses an external provider component, CommandText represents a replacement for the property that the source dataset uses to identify its data (the SQL of a query, or the name of a table or stored procedure). If the provider's Options property does not include poAllowCommandText (which, by default, it does not), then CommandText has no effect. 

When CommandText is a non-empty string, its value is sent to the provider when the client dataset opens or when you call the Execute method. The specified SQL command, table, or stored procedure overrides the current value of the provider's associated dataset. 

If the SQL statement takes parameters, be sure that they are in the correct order, as the provider performs parameter binding on CommandText statements by index only.  

Delphi Examples: 

 

{
The following code fragment illustrates how DataSets and
DataSetCount can be used to ensure that an action is taken
for every open dataset.  Assign CheckButtonActive as the
AfterClose and AfterOpen event handlers for TClientDataSet1.
}
procedure TForm1.Button1Click(Sender: TObject);
var
  I: Integer;
begin
  if not RemoteServer1.Connected then
    RemoteServer1.Connected := True;
  ClientDataSet1.Close;
  with RemoteServer1 do
  begin
    for I := 0 to DataSetCount - 1 do
      DataSets[I].EnableControls;
  end;
  // Memo1 must contain a "select * from xxx" employee, customer, client
  // Look in Program Files/Common Files/CodeGear Shared/Data for db files
  // Notice, using the CommandText, don't need a BeforeGetRecords event
  // handler for the ClientDataSet or the DataSetProvider.

  ClientDataSet1.CommandText := Memo1.Lines.Text;
  ClientDataSet1.Open;
end;

 

Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
What do you think about this topic? Send feedback!