Using TStoredProc
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
- Choose File > New > Other. The New Items dialog appears.
- In the New Items dialog, select Delphi Projects and double-click VCL Forms Application.The Windows Designer displays.
- Associate a dataset with database and session connections.
- Bind the parameters.
To associate a dataset with database and session connections
- From the BDE category of the Tool Palette, drag a TDatabase component to the form.
- 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.
- Drag a TSession component to the form.
- To control all database connections in your application, use the default session.
- 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
- From the BDE category of the Tool Palette, drag a TStoredProc component to the form.
- Set the ParamBindMode property to default pbByName to specify how parameters should be bound to the parameters on the server.
- View the stored procedure source code of a server in the SQL Explorer if you want to set ParamBindMode to pbByNumber.
- Determine the correct order and type of parameters.
- 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.