Navigational Actions with ADS and ADO.NET

Most of the navigational features that you can access with other data access mechanisms, such as ADO and TDataSet, are implemented in the ADO.NET DataSet class. For example, indexing, sorting, filtering, and seeking are all operations that are performed on a DataSet’s cached records. In other words, these operations do not involve ADS, other than using ADS as the original source of the data that is manipulated in memory.

There is, in fact, only one ADO.NET navigational operation that involves ADS scanning. Specifically, using an AdsDataReader, you can perform a record-by-record navigation of data. This operation is demonstrated in the following section.

Scanning a Result Set

Scanning is the process of sequentially reading every record in a result, or every record in the filtered view of the result set if a filter is active. In ADO.NET, scanning is performed using an AdsDataReader, which you obtain from an AdsCommand object that contains a SQL SELECT statement.

You obtain an AdsDataReader from an AdsCommand object by calling its ExecuteReader method. You then invoke the AdsDataReader’s Read method to access the first record in the result set. Repeated calls to Read fetch additional records, until the entire result set has been traversed. When no records remain in the result set, Read evaluates to a Boolean False.

After successfully fetching a record through an AdsReader’s Read method, you can read individual fields of the fetched record by calling an appropriate AdsReader getter method. For example, you call GetString to read a string field, and call GetInt32 to read an integer field. When you call a getter method, you indicate which field you want to read by passing either the ordinal position of that field in the table’s structure, or a string that identifies the field.


If you are using ADS, and you must scan a large number of records, consider implementing the operation using an AEP (Advantage Extended Procedure) as described in Chapter 7. Scanning from an AEP installed on ADS requires no network resources.

The following code demonstrates scanning using an AdsDataReader. This code is associated with the List Products button (shown in Figure 15-1):

private void listProductsBtn_Click(object sender,   System.EventArgs e) {   command.CommandText = "SELECT * FROM PRODUCTS";   dataReader = command.ExecuteReader();   while (dataReader.Read()) {   productList.Items.Add(dataReader.GetString(0) + "  " +   dataReader.GetString(1));   }   dataReader.Close(); }

In addition to the Read method, the AdsDataReader supports ReadPrevious. Also, it is possible that future versions of AdsDataReader will support additional navigational methods. See the ADS help for more information.

Advantage Database Server. The Official Guide
Advantage Database Server: The Official Guide
ISBN: 0072230843
EAN: 2147483647
Year: 2002
Pages: 129 © 2008-2017.
If you may any questions please contact us: