Specifying the Data to Display using TSQLDataSet
Go Up to Using dbExpress
To specify the data to display
- 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.
- From the dbExpress category of the Tool Palette, drag a TSQLDataSet component to the form.
- For TSQLDataSet, specify the type of unidirectional dataset by CommandType property in the Object Inspector.
- Specify whether information comes from results of query, a database table, or a stored procedure.
To display results from a query
- Set the CommandType property to ctQuery for a TSQLDataSet.
- For TSQLQuery, drag a TSQLQuery component from the Tool Palette to the form.
- Set the SQL property to the query you want to assign.
- Select TSQLDataSet.
- Click the CommandText property. The CommandText Editor opens.
- In the CommandText Editor, set the SQL property to the text of the query statement.
Note: When you specify the query, it can include parameters or variables, the values of which can be varied at design time or run time. Parameters can replace data values that appear in the SQL statement. SQL defines queries such as UPDATE queries that perform actions on the server but do not return records.
To display records in a table
- In the Object Inspector, set the CommandType property to ctTable. TSQLDataSet generates a query based on the values of two properties: CommandText, which specifies the name of the database table that the TSQLDataSet object should represent and SortFieldNames, which lists the names of any fields to use to sort the data, in the order of significance.
- Drag a TSQLTable component to the form.
- In the Object Inspector , set the TableName property to the table you want.
- Set the IndexName property to the name of an index defined on the server or set the IndexFieldNames property to a semicolon-delimited list of field names to specify the order of fields in the dataset.
To display the results of a stored procedure
- In the Object Inspector, set the CommandType property to ctStoredProc.
- Specify the name of the stored procedure as the value of the CommandText property.
- Set the StoredProcName property to the name of the stored procedure for TSQLStoredProc.
Note: After you have identified a stored procedure, your application may need to enter values for any input parameters of the stored procedure or retrieve the values of output parameters after you execute the stored procedure.