Difference between revisions of "Working With TSQLQuery"

From Lazarus wiki
Jump to navigationJump to search
Line 6: Line 6:
 
The code can, of  course, be written on one line but has been broken up for clarity.
 
The code can, of  course, be written on one line but has been broken up for clarity.
  
The data set returned by TSQlQuery can conveniently be viewed with an instance of TDBGrid, but it is not very suitable for editing the data in the individual fields and cells. For this purpose you need to place some Data-Aware single-field controls such as TDBEdit on your form, and set their DataSource popertuy to the data source eing used. The DataField property should be set to either a numbered column (eg DataSet.Fields[0]) or to a named field (eg 'IDENTITY').
+
The data set returned by TSQlQuery can conveniently be viewed with an instance of TDBGrid, but it is not very suitable for editing the data in the individual fields and cells. For this purpose you need to place some Data-Aware single-field controls such as TDBEdit on your form, and set their DataSource poperty to the data source being used. The DataField property should be set to a named field (eg 'IDENTITY') or to some expression that returns a suitable string.
  
 
Addition of a TDBNavigator toolbar makes it very easy to navigate through the records, and to select records for editing. When a record is selected by the toolbar or by moving the mouse through the data grid, the data for the relevant row and column appear in the TDBEdit box and if the 'Edit' button is clicked, the contents in the Edit box can be modified. Clicking on the 'Post' button confirms the change, or clicking on the 'Cancel' button cancels the changes.
 
Addition of a TDBNavigator toolbar makes it very easy to navigate through the records, and to select records for editing. When a record is selected by the toolbar or by moving the mouse through the data grid, the data for the relevant row and column appear in the TDBEdit box and if the 'Edit' button is clicked, the contents in the Edit box can be modified. Clicking on the 'Post' button confirms the change, or clicking on the 'Cancel' button cancels the changes.

Revision as of 19:56, 3 February 2008

If you need to be able to DELETE or otherwise modify records, your database table should contain one PRIMARY KEY column that has the property AUTO_INCREMENT. This enables the DELETE method to identify the records marked for deletion in the 'WHERE' clause written back to the database. The primary key field should preferably be designed into the table structure at CREATE time, but can be added using the following example code in your MySQL client:

 alter table testrig 
 add column autoid int 
 primary key auto_increment;

The code can, of course, be written on one line but has been broken up for clarity.

The data set returned by TSQlQuery can conveniently be viewed with an instance of TDBGrid, but it is not very suitable for editing the data in the individual fields and cells. For this purpose you need to place some Data-Aware single-field controls such as TDBEdit on your form, and set their DataSource poperty to the data source being used. The DataField property should be set to a named field (eg 'IDENTITY') or to some expression that returns a suitable string.

Addition of a TDBNavigator toolbar makes it very easy to navigate through the records, and to select records for editing. When a record is selected by the toolbar or by moving the mouse through the data grid, the data for the relevant row and column appear in the TDBEdit box and if the 'Edit' button is clicked, the contents in the Edit box can be modified. Clicking on the 'Post' button confirms the change, or clicking on the 'Cancel' button cancels the changes.