Main Page

moveFirst

The first step in the previous code is to set the recordset to the first record. The
while
loop then tests
EOF, which is
true
when the end of the file has been reached. Inside of the loop is where the data pro-
cessing occurs before moving on to the next record.
It’s also possible to move backwards through the recordset using the opposite methods:
oDataset.moveLast();
while (!oDataset.BOF) {
//do something with the data here
oDataset.movePrevious();
}
This code starts from the last record and works its way back to the first. The
BOF
property is equal to
true
when you reach the beginning of the file.
To get at the data, use the
fields()
method of the recordset with the column name (either
first_name
or
last_name
in the previous example) or the position of the column, starting at 0, in the table. This
method returns an object representing the field that has a
value
property with the actual value. So to
display the first name for each person in
Names.txt
, the following code can be used:
oDataset.moveFirst();
while (!oDataset.EOF) {
alert(oDataset.fields(0).value);
oDataset.moveNext();
}
You could also use
first_name
instead of
0
:
oDataset.moveFirst();
while (!oDataset.EOF) {
alert(oDataset.fields(“first_name”).value);
oDataset.moveNext();
}
In this way, you can move through the recordset and get all the data you need.
The tabular data control is a useful component if you have the luxury of developing only for Internet
Explorer on Windows. It has a great many uses for it, many more than can be discussed in this context.
Its tie to both Internet Explorer as a browser and Windows as a platform has, however, greatly inhibited
its use and adoption in Web development. Presently, such solutions are best suited for Intranet applica-
tions where the user base can be kept to those using IE on Windows exclusively.
560
Chapter 18
21_579088 ch18.qxd 3/28/05 11:43 AM Page 560


JavaScript EditorFree JavaScript Editor     Ajax Editor


©