RecordSet.FieldCount

From Xojo Documentation

Read-Only Property (As Integer )
IntegerValue = aRecordSet.FieldCount

Supported for all project types and targets.

The number of fields in the RecordSet.

Sample Code

The following method populates a ListBox with a RecordSet. Is uses FieldCount to create the header for the ListBox with the names of the columns in the table:

Sub PopulateListBox(dataList As Listbox, rs As RecordSet)
If rs Is Nil Then Return

// set up listbox state for population
dataList.DeleteAllRows

// Add the DB columns as the headers for the ListBox
dataList.ColumnCount = rs.FieldCount
dataList.Column(-1).WidthExpression = "100"
For i As Integer = 0 To rs.FieldCount - 1
dataList.Heading(i) = rs.IdxField(i + 1).Name
Next

// Add the data from the table
While Not rs.EOF
dataList.AddRow("")

For i As Integer = 0 To rs.FieldCount - 1
dataList.Cell(dataList.LastIndex, i) = rs.IdxField(i + 1).StringValue
Next

rs.MoveNext
Wend
End Sub