5. Working with a Database : How You Can Access a Database with DataStream Objects : How You Can Use SQLSelect Objects : How You Can Get Next and Previous Rows
 
Share this page                  
How You Can Get Next and Previous Rows
Suppose that your frame has buttons labeled Next and Previous. The following code shows how you can use these buttons to fetch the next and previous rows:
/*
** Initialize the buttons.
*/
if (ss.CurRow >1) then
        field(prev_btn).CurBias = FB_CHANGEABLE;
else
       field(prev_btn).CurBias = FB_DIMMED;
endif;
if (ss.CurRow <ss.MaxRow) then
        field(next_btn).CurBias = FB_CHANGEABLE;
else
        field(next_btn).CurBias = FB_DIMMED;
endif;\
...
on click next_btn =
{
ss.NextRow();
ss.Load();
/*
** Display the data.
*/
...
/*
** See if there are more rows.
*/
if (ss.CurRow >= ss.MaxRow) then
    field(next_btn).CurBias = FB_DIMMED);
endif;
field(prev_btn).CurBias = FB_CHANGEABLE;
}
on click prev_btn =
{
ss.PrevRow();
ss.Load();
/*
** Display the data.
*/

if (ss.CurRow <= 1) then
    field(prev_btn).CurBias = FB_DIMMED);
endif;
field(next_btn).CurBias = FB_CHANGEABLE;
}
A third DataStream method used to get rows is the FetchRow method. This method sets the current row in the cache to the row specified in the RowIndex parameter. The value of this parameter must be an integer.
For example, the following code sets the fourth row in the cache as the next row to be loaded:
ss.FetchRow(rowindex = 4);
To position the current row on the first row of the cache, set the RowIndex parameter to “1”, for example:
ss.FetchRow(rowindex = 1);
Both the PrevRow and FetchRow methods are valid only in QY_CACHE mode.