Setting up a simple dataset requires two essential steps. Set up:
- The connection information.
- The dataset information.
The following steps describe setting up a simple dataset in more detail.
To use TSimpleDataSet:
- Place the TSimpleDataSet component in a data module or on a form. Set its Name property to a unique value appropriate to your application.
- Identify the database server that contains the data. There are two ways to do this:
- If you have a named connection in the connections file, expand the Connectionproperty and specify the ConnectionName value.
- For greater control over connection properties, transaction support, login support, and the ability to use a single connection for more than one dataset, use a separate TSQLConnection component instead. Specify the TSQLConnection component as the value of the Connection property. For details on TSQLConnection, see Connecting to databases.
- To indicate what data you want to fetch from the server, expand the DataSet property and set the appropriate values. There are three ways to fetch data from the server:
- Set CommandType to ctQuery and set CommandText to an SQL statement you want to execute on the server. This statement is typically a SELECT statement. Supply the values for any parameters using the Params property.
- Set CommandType to ctStoredProc and set CommandText to the name of the stored procedure you want to execute. Supply the values for any input parameters using the Params property.
- Set CommandType to ctTable and set CommandText to the name of the database tables whose records you want to use.
- If the data is to be used with visual data controls, add a data source component to the form or data module, and set its DataSet property to the TSimpleDataSet object. The data source component forwards the data in the client dataset's in-memory cache to data-aware components for display. Connect data-aware components to the data source using their DataSource and DataField properties.
- Activate the dataset by setting the Active property to true (or, at runtime, calling the Open method).
- If you executed a stored procedure, use the Params property to retrieve any output parameters.
- When the user has edited the data in the simple dataset, you can apply those edits back to the database server by calling the ApplyUpdates method. Resolve any update errors in an OnReconcileError event handler. For more information on applying updates, see Updating records.