Using TStoredProc

From RAD Studio
Jump to: navigation, search

Go Up to How To Perform Database Procedures

TStoredProc is a stored procedure-type dataset that executes a stored procedure that is defined on a database server.

To use TStoredProc

  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. Associate a dataset with database and session connections.
  4. Bind the parameters.

To associate a dataset with database and session connections

  1. From the BDE category of the Tool Palette, drag a TDatabase component to the form.
  2. To associate a BDE-enabled dataset with a database, set the DatabaseName property. For TDatabase component, database name is the value of the DatabaseName property of the database component.
  3. Drag a TSession component to the form.
  4. To control all database connections in your application, use the default session.
  5. In the Object Inspector, set the SessionName property of the TSession component to associate your dataset with an explicitly created session component.

Note: If you use a session component, the SessionName property of a dataset must match the SessionName property for the database component with which the dataset is associated.

To bind parameters

  1. From the BDE category of the Tool Palette, drag a TStoredProc component to the form.
  2. Set the ParamBindMode property to default pbByName to specify how parameters should be bound to the parameters on the server.
  3. View the stored procedure source code of a server in the SQL Explorer if you want to set ParamBindMode to pbByNumber.
  4. Determine the correct order and type of parameters.
  5. Specify the correct parameter types in the correct order.

Note: Some servers also support binding parameters by ordinal value, the order in which the parameters appear in the stored procedure. In this case the order in which you specify parameters in the parameter collection editor is significant. The first parameter you specify is matched to the first input parameter on the server, the second parameter is matched to the second input parameter on the server, and so on. If your server supports parameter binding by ordinal value, you can set ParamBindMode to pbByNumber.

See Also