Home > Language Reference > Classes > Recordset
SelectFields Method
Selects a subset of fields.
Syntax
Public Sub SelectFields(ByRef sFieldList As String)
| Parameter | Description |
| sFieldList | Field list, comma separated. |
Remarks
Each time the cursor is moved to a new position, a record is loaded from the storage heap and mapped to the various member variables of the Recordset object, so that fields values are updated. This mechanism can be time consuming, especially if your table contains numerous variable length objects, such as strings or bitmaps, and if you browse an entire table containing thousands of records.
The SelectFields method allows you to restrict the number of fields that are mapped to the physical record. The sFieldList parameter is a string specifying the names of the fields to be selected, separated by commas. The wildcard character * can be used to indicates that all fields must be mapped again.
The following example illustrates this. A list is filled with a whole table. To improve performances, only the fields that will be displayed are loaded:
Dim rs As New tblCustomer rs.SelectFields "UniqueID, Name" rs.OpenTable hbModeOpenExisting+hbModeReadOnly While Not rs.EOF List1.AddItem rs.UniqueID & " " & rs.Name rs.MoveNext Wend rs.SelectFields "*"
You can call the SelectFields method at any moment, including before the database is opened or after it is closed. If you request more fields to be loaded and the cursor is located on a valid record, those fields are immediately loaded. The following example uses this behavior to perform a complex query as fast as possible:
Dim rs as New tblCustomer
rs.SelectFields "Date1, Date2"
rs.OpenTable hbModeOpenExisting+hbModeReadOnly
While Not rs.EOF
If rs.Date2-rs.Date1>5.0 Then
rs.SelectFields "*" ' Load the whole record
List1.AddItem rs.UniqueID & " " & rs.Name
rs.SelectFields "Date1, Date2" ' Mask unused fields again
End If
rs.MoveNext
WendFields that are not mapped contain unpredictable values.
Sometimes, depending on memory alignment, it may be faster to load the whole record in one go than to load it by parts. Therefore, the database engine may choose to load much more fields than you specified in a call to SelectFields.
Note: this method does not perform any validation on the field list it is passed. If one of the specified names does not correspond to an actual field in this recordset, it is simply ignored.
System requirements
| System | Minimal version | Remarks |
| Palm OS | Palm OS 3.0 | - |
| Windows CE | Windows CE 3.0 | - |