RAD Studio |  |

Representing the Records in a Table
Representing a table using TSQLDataSet | Representing a table using TSQLTable | See Also
Collapse All

When you want to represent all of the fields and all of the records in a single underlying database table, you can use either TSQLDataSet or TSQLTable to generate the query for you rather than writing the SQL yourself.

Note: If server performance is a concern, you may want to compose the query explicitly rather than relying on an automatically-generated query. Automatically-generated queries use wildcards rather than explicitly listing all of the fields in the table. This can result in slightly slower performance on the server. The wildcard (*) in automatically-generated queries is more robust to changes in the fields on the server.
Representing a table using TSQLDataSet

To make TSQLDataSet generate a query to fetch all fields and all records of a single database table, set the CommandType property to ctTable.

When CommandType is ctTable, TSQLDataSet generates a query based on the values of two properties:

- CommandText specifies the name of the database table that the TSQLDataSet object should represent.
- SortFieldNames lists the names of any fields to use to sort the data, in the order of significance.

For example, if you specify the following:
Copy Code

    SQLDataSet1.CommandType := ctTable;
    SQLDataSet1.CommandText := 'Employee';
    SQLDataSet1.SortFieldNames := 'HireDate,Salary'

Copy Code

    SQLDataSet1->CommandType = ctTable;
    SQLDataSet1->CommandText = "Employee";
    SQLDataSet1->SortFieldNames = "HireDate,Salary"

TSQLDataSet generates the following query, which lists all the records in the Employee table, sorted by HireDate and, within HireDate, by Salary:

Copy Code

    select * from Employee order by HireDate, Salary

Representing a table using TSQLTable

When using TSQLTable, specify the table you want using the TableName property.

To specify the order of fields in the dataset, you must specify an index. There are two ways to do this:

- Set the IndexName property to the name of an index defined on the server that imposes the order you want.
- Set the IndexFieldNames property to a semicolon-delimited list of field names on which to sort. IndexFieldNames works like the SortFieldNames property of TSQLDataSet, except that it uses a semicolon instead of a comma as a delimiter.

See Also

Representing the Results of a Stored Procedure

Representing the Results of a Query

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