RAD Studio |  |

Using Stored Procedure-type Datasets
See Also
Collapse All

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

1. 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.
2. 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. For information about using database connection components, see Connecting to databases
3. 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.
4. 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.
5. 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.
6. Execute the stored procedure. For stored procedures that return a cursor, use the Active property or the Open method. To execute stored procedures that do not return any results or that only return output parameters, use the ExecProc method at runtime. If you plan to execute the stored procedure more than once, you may want to call Prepare to initialize the data access layer and bind parameter values into the stored procedure. For information about preparing a query, see Preparing stored procedures.
7. 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.

See Also

Using Table Type Datasets

Using Query-type Datasets

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