Navigation:  Programming Cookbook > Database Connectivity > Executing SQL Queries >

Navigating through a Result Set

Previous pageReturn to chapter overviewNext page

The result set we have just obtained from the previous query should contain a number of rows of data. The DBResultSet class gives us a number of methods for navigating through the rows. Try the following examples to see how you can access the available data.

rs first. "Display it"

rs next. "Display it"

rs next. "Display it"

rs last. "Display it"

rs prev. "Display it"


Although not particularly efficient, you can also treat a DBResultSet as any other in memory collection (it is a subclass of ArrayedCollection). For example, you can collect all of the shipping names from the Orders table using:

rs collect: [:x | x ShipName]. "Inspect it"


The rows in the set can also be addressed by their index location:

rs at: 1. "Display it"

rs at: 100. "Display it"