Using Stored Procedure-type Datasets
Go Up to Understanding Datasets Index
How your application uses a stored procedure depends on how the stored procedure was coded, whether and how it returns data, the specific database server used, or a combination of these factors.
To access a stored procedure on a server
- Place the appropriate dataset component in a data module or on a form, and set its Name property to a unique value appropriate to your application.
- Identify the database server that defines the stored procedure. Each stored procedure-type dataset does this differently, but typically you specify a database connection component:
- For TStoredProc, specify a TDatabase component or a BDE alias using the DatabaseName property.
- For TADOStoredProc, specify a TADOConnection component using the Connection property.
- For TSQLStoredProc, specify a TSQLConnection component using the SQLConnection property.
- For TIBStoredProc, specify a TIBConnection component using the Database property.
- Specify the stored procedure to execute. For most stored procedure-type datasets, you do this by setting the StoredProcName property. The one exception is TADOStoredProc, which has a ProcedureName property instead.
- If the stored procedure returns a cursor to be used with visual data controls, add a data source component to the data module, and set its DataSet property to the stored procedure-type dataset. Connect data-aware components to the data source using their DataSource and DataField properties.
- Provide input parameter values for the stored procedure, if necessary. If the server does not provide information about all stored procedure parameters, you may need to provide additional input parameter information, such as parameter names and data types. For information about working with stored procedure parameters, see Working with stored procedure parameters.
- Execute the stored procedure. For stored procedures that return a cursor, use the Active property or the Open method from Preparing Stored Procedures.
- Process any results. These results can be returned as result and output parameters, or they can be returned as a result set that populates the stored procedure-type dataset. Some stored procedures return multiple cursors. For details on how to access the additional cursors, see Fetching multiple result sets.