Show: Delphi C++
Display Preferences

Setting Up a Simple Dataset

From RAD Studio
Jump to: navigation, search

Go Up to Using a Simple Dataset


Setting up a simple dataset requires two essential steps. Set up:

  1. The connection information.
  2. The dataset information.

The following steps describe setting up a simple dataset in more detail.

To use TSimpleDataSet:

  1. Place the TSimpleDataSet component in a data module or on a form. Set its Name property to a unique value appropriate to your application.
  2. 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 Connection property 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 TSimpleDataSet's Connection property.
  3. 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.
  4. 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.
  5. Activate the dataset by setting the Active property to true (or, at run time, calling the Open method).
  6. If you executed a stored procedure, use the Params property to retrieve any output parameters.
  7. When the user has edited the data in the simple dataset, you can apply those edits back to the database server by calling the Updating records.

See Also

Code Examples

Personal tools
In other languages
Previous Versions
Assistance