| << 13.1.0- The Recordset Object | Chapter13 | 13.1.2- Creating a Recordset >> |
What is a Recordset?
In the previous chapter , we talked about the notion of an employee record being a collection of (one or more) values, for different types of data that all relate to a particular thing. We gave the example of the employee record:
|
Employee Key |
Name |
Address 1 |
Address 2 |
City |
State |
Zip |
Phone |
|
A100 |
Chris Ullman |
29 LaSalle Street |
Suite B01 |
Chicago |
Illinois |
60603 |
392-893-8004 |
This is just a single record. This record contains a number of pieces of data – one for each of the fields 'Employee Key', 'Name', 'Address 1', etc. Each piece of data is information about this employee, on the subject of that field.
Now imagine a whole collection of records just like this one. Each record pertains to one individual employee, and the information in that record is information about that employee. Moreover, each record has the same structure – that is, it represents values of the same fields ('Employee Key', 'Name', 'Address 1', etc.) in the same order:
|
Employee Key |
Name |
Address 1 |
Address 2 |
City |
State |
Zip |
Phone |
|
A192 |
Chris Masters |
29 LaSalle Street |
Suite 278 |
Chicago |
Illinois |
60603 |
392-893-8103 |
|
A203 |
David Minter |
42 Downing Alley |
Room 29 |
Oxford |
Oxon |
OX98 1QY |
1865-000000 |
|
A229 |
John Morrissey |
29 LaSalle Street |
Suite 502 |
Chicago |
Illinois |
60603 |
392-893-8115 |
This is a set of records – or a recordset. This recordset has three records in it – one record each for the information of Messrs Masters, Minter and Morrissey. In order to define this recordset, we've chosen a particular set of fields (i.e. the 'classes' of information that we've selected in the top row of the table) and some criterion specifying which records we're interested in (e.g. here we wanted to know about employees whose surname begins with 'M', but none of our other employees).
In ADO, we represent a recordset – the data received when we query the database – by using its Recordset object. In fact, an ADO Recordset object is more than just a set of related data, like the table shown above – it has functionality to allow us to manipulate data, add, remove or hide records, search for data within the record, and so on. We'll meet much of this functionality during the course of this chapter.
Recordsets and Cursors
In addition, an ADO Recordset uses something called a cursor. A cursor is a 'pointer', which points to one of the records in the recordset, thus indicating our current position in the recordset.
Every active Recordset object has a cursor, and at any given time, the cursor is pointing to exactly one of the records in the recordset.
What's the cursor for? Predominantly, it's there to help us to find our way around the records of a Recordset object. We can move the cursor so that it points to exactly the single record that we're interested in; and then we can use the names of the fields to single out individual 'cells' of information. There are various ways of moving the cursor around – for example, we can search the recordset for a particular record, or we can use special Recordset methods called MoveFirst, MoveLast, MoveNext and MovePrevious (which we'll meet later in the chapter).
For example, in order to find John Morrissey's telephone number we can instruct the cursor to move to Mr Morrissey's record (either by 'searching' for that record, or – in this case – using the MoveLast method). In the following table, the asterisk (*) on the left-hand side indicates the position of the cursor:
|
Employee Key |
Name |
Address 1 |
Address 2 |
City |
State |
Zip |
Phone |
|
A100 |
Chris Masters |
29 LaSalle Street |
Suite 278 |
Chicago |
Illinois |
60603 |
392-893-8103 |
|
A203 |
Alan Minter |
42 Downing Alley |
Room 29 |
Oxford |
Oxon |
OX98 1QY |
1865-000000 |
|
*A229 |
John Morrissey |
29 LaSalle Street |
Suite 502 |
Chicago |
Illinois |
60603 |
392-893-8115 |
Then we can ask for the Phone field of the current record.
| << 13.1.0- The Recordset Object | Chapter13 | 13.1.2- Creating a Recordset >> |

RSS

