0% found this document useful (0 votes)
5 views3 pages

ADO - Summary Sheet

The document outlines basic table methods for managing records in a database, including navigating, adding, editing, and deleting records. It provides examples of how to display all or specific records based on criteria, as well as handling user interactions for selecting and modifying records. Additionally, it explains how to work with multiple tables simultaneously to perform operations like summing prices based on supplier information.

Uploaded by

ash.marais69
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views3 pages

ADO - Summary Sheet

The document outlines basic table methods for managing records in a database, including navigating, adding, editing, and deleting records. It provides examples of how to display all or specific records based on criteria, as well as handling user interactions for selecting and modifying records. Additionally, it explains how to work with multiple tables simultaneously to perform operations like summing prices based on supplier information.

Uploaded by

ash.marais69
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

ADO Summary Sheet

Basic Table Methods:


.FIRST → moves file pointer to the first record in the table.
.NEXT → moves file pointer to the next record in the table.
.LAST → moves file pointer to the last record in the table.
.PRIOR → moves file pointer to the previous record in the table.
.APPEND → adds a new record to the end of the table.
.INSERT → inserts a new record at the file pointer position.
.DELETE → deletes the record at the current file pointer position from the table.
.EDIT → allows changes to be made to the field values of the current record.
.POST → saves the changes made to the table in RAM to the version on the storage device.
.EOF → tests if the file pointer is at the end of the file.
.RECORDCOUNT → returns the number of records in the table.

Format of working with one of the fields in a table: sName := tableName[‘field name’];

BASIC FRAMEWORKS:
Display All To display all the records in a database table. tblBikes.First;
While tblBikes.EOF = False do
Begin
Casting of data types is necessary. red.lines.add(tblBikes[‘Name’] + #9 +
(FloatToStrF(tblBikes[‘Price’]);
NB: .Next moves to the next record. Will result tblBikes.Next;
in an infinite loop if left out. End;

Display Some Display records based on a certain criteria, eg. tblBikes.First;


All Bikes with a price greater than R75000. While tblBikes.EOF = False do
Begin
Any calculation can also be done in the loop, IF tblBikes[‘Price’] > 75000
e.g. sum, highest, lowest, etc. Then red.lines.add(tblBikes[‘Name’]) + #9 +
(FloatToStrF(tblBikes[‘Price’]);
tblBikes.Next;
End;

Alternative loop Instead of a While, you could use a For Loop tblBikes.First;
method For iLoop := 1 to tblBikes.Recordcount do
Begin
red.lines.add(tblBikes[‘Name’]);
tblBikes.Next;
End;
Add records NO loop when adding. tblBikes.Append;
(Append/Insert) tblBikes[‘Name’] := edtBikeName.text;
Two methods (you may use any): tblBikes[‘Price’] := StrToFloat(edtPrice.text);
Append adds to the end of the table. tblBikes.Post;

Insert adds at the current position. To add to the Or


end, you need to go to the last record.
tblBikes.Last;
NB: Remember to save (POST) tblBikes.Insert;
tblBikes[‘Name’] := edtBikeName.text;
tblBikes[‘Price’] := StrToFloat(edtPrice.text);
tblBikes.Post;

Edit records To edit a particular record, tblBikes.First;


● Find the record (if inside loop), While tblBikes.eof = false do
● Put the table in edit mode Begin
● Make the change IF sFind = tblBikes[‘name’] then
● Save the change using post. Begin
tblBikes.Edit; //must be inside IF
NB: . NEXT takes the table out of edit mode. tblBikes[‘Price’] := tblBikes[‘Price’] * 1.15;
Therefore .EDIT must be inside loop (and inside tblBikes.Post;
IF) End;
tblBikes.Next;
end;

Delete records To delete a particular record, tblBikes.First;


● Find the record (IF inside loop) While tblBikes.eof = false do
● Delete the record Begin
● DO NOT go to the next record because IF sFind = tblBikes[‘name’] then
all records shifted up one position to Begin
replace deleted records. Add the .next in tblBikes.Delete;
the ELSE section. End
ELSE tblBikes.Next;
end;

Delete, edit Use a boolean flag to stop the loop as soon as a tblBikes.First;
ONE record particular record is deleted or edited. Bfound := false;
(depends on the question). While (tblBikes.eof = false) AND (bfound = false) do
Example is of a delete, but the same principle is Begin
to be followed for edit. IF sFind = tblBikes[‘name’] then
Begin
tblBikes.Delete;
bFound := true;
End
ELSE tblBikes.Next;
end;

ONCLICK When a table is displayed in a dgGrid, EXAMPLE of displaying the ACTIVE record:
The user can select a record by clicking on it. pnlBikeName.caption := tblBikes[‘Names’] ;
pnlBikePrice.caption := FloatToStr(tblBikes[‘Price’]);
That record is then the ACTIVE record,
And can be displayed, edited or deleted EXAMPLE of deleting the ACTIVE record:
WITHOUT having to search for it (using a loop) IF MessageDLG(‘You want to delete: ‘+tblBikes[‘names’],
mtConfirmation, mbYesNo, 0) = mrYes
The active record will have an arrow in front of it. Then begin
tblBikes.Delete;
ALWAYS ask for confirmation when editing showmessage(‘deleted’);
or deleting by using a messagedlg or end;
inputbox.

Double Tables Based on the question, you might have to work //first table - primary table
with two tables at the same time. tblBikesSuppliers.First;
E.g. BikesSuppliers and BikesInfo While tblBikesSuppliers.EOF = false do
Begin
Question: rSum := 0; //new sum for each supplier
Determine the total Bike prices for each Bike sSupplierID := tblBikesSuppliers[‘SuppID’]; //primaryKey
supplier.
Prices from BikesInfo, //second table - inside loop
Supplier Name from BikesSuppliers tblBikes.First; //NB → bring filepointer to top
While tblBikes.Eof = False do //inside loop finds all
//prices for that supplier
Begin
If sSupplierID = tblBikes[‘SupplierID’]//foreignKey
Then rSum := rSum + tblBikes[‘price’];
End; //inside loop

red.lines.add(tblBikesSuppliers[‘supplierName’] + #9+
FloatToStr(rSum) );
End; //outside loop

You might also like