Académique Documents
Professionnel Documents
Culture Documents
These methods correspond to the buttons on the DBNavigator control. You can, if you wish, create your own buttons to replace the DBNavigator, in which
case you need to set each button to carry out a discrete operation such as inserting an empty record, allowing the user to enter data and then saving the
new data with a new button.
Replacing the DBNavigator bar is a matter of form design. You may think, probably correctly, that the DBNavigator bar is a little intimidating for a new user
so you prefer to create your own friendly buttons with more descriptive labels such as 'Insert New Record' and 'Save New Record'.
First
Moves the file pointer to the first record in the table. Contents of the record should be displayed in any ADO data fields. Any button that calls First or Prior
should now be disabled so the user cannot request an action that cannot be completed. Any button that calls Next or Last should probably be enabled.
Prior
Sets current record to the one before the current record. Any buttons calling the Next or Last methods should be enabled at this point.
Next
Moves the file pointer to the next record in the table. Contents of the record should be displayed in any ADO data fields. Any buttons calling the Prior or First
methods should be enabled at this point.
Last
Moves the file pointer to the last record in the table. Contents of the record should be displayed in any ADO data fields. Any buttons calling the Last or Next
methods should be disabled at this point.
Insert
Inserts a new record before the current record and puts the dataset into Insert and Edit modes.
Delete
Deletes the current record and makes the next record the current one.
Edit
Puts the dataset into edit mode so the current record can be edited.
Post
Writes the change to the current record in the database.
Cancel
Cancels edits to the current record, restores the record display to its condition prior to editing, and turns off Insert and Edit states if they are active.
Refresh
Refreshes the buffered data in the associated dataset.
Locate
This command locates (finds) a record in a table from the field information supplied. For example:
ADOTable1.Locate('CDTitle',combobox3.Text,[]);
This is a whole lot better than constructing your own search routine using while not table.eof do...
The parameters are: the field name in the table, the value sought and a pair of empty square brackets.
Example 1
In this example a link is made to database and fields are extracted from an ADO table object. An edit box is provided so the user can find a team by name.
Code:
The user can enter the name of a team to find in the box. The code uses the next procedure to scan through the ADO table until the requested record is
found. If the record is not found then a message is displayed and the table pointer is moved to the first record.
Example 2
In this example we place two buttons on a form, one to insert a new record and the other to save it.
The form after pressing the Insert New Record button and adding some text.
Additional buttons could be added to edit the current record and save (post) changes, or to delete records.
Example 3
In this example there are two list boxes on a form, one for CD titles and the other for the tracks on each one. When a user clicks on a CD title in the first list
box the tracks of that CD are shown in the second list box.
The code for loading the CD titles into the first list box is:
This scans the first table for a match between the selected title and the titles in a database table. When a match is found the serial number of the CD is
copied into a variable for use in the second part of the procedure. This technique is useful in situations where the user is choosing a data item that is not the
primary key but where the primary key is required later on. There is a potential problem here in that two CDs could have the same title (e.g. Greatest Hits).
In the second part of the code the primary key, serial_number, is used to identify tracks that include it as their foreign key so that they can be displayed in
the second list box.
Example 4
In this example we see how we can populate two combo boxes from two ADO tables. The first combo box is populated from a table that includes company
department details. When a department is selected the second combo box is populated with the members of the department, which are taken from the
second table. This process involves a fair amount of manipulation of the contents of the ADO tables to identify the items required and place them in the
boxes. As the names are chosen from the second combo box one of two buttons on the form is enabled.
end;
adotable2.Next;
end;
adotable2.Close;
populatecombo1;
end;