|
Scanning a Result Set Advantage Database Server v8.1: A Developer’s Guide by Cary Jensen and Loy Anderson © 2007 Cary Jensen and Loy Anderson. All rights reserved. |
|
|
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 or AdsExtendedReader, which you obtain from an AdsCommand object that contains either a SQL SELECT statement, a table name, or a stored procedure call.
TIP: If you are using ADS, and you must scan a large number of records, consider implementing the operation using a stored procedure as described in Chapter 7. Scanning from a stored procedure installed on the same machine on which the data resides requires no network resources.
The following code demonstrates scanning using an AdsDataReader. This code is associated with the List Products button shown in Figure 18-3:
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();
}