<div class="meta" robots="noindex">

</div>

Class

# RecordSet

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

<div class="warning">

<div class="title">

Warning

</div>

This item was deprecated in version 2019r2. Please use `RowSet</api/databases/rowset>` as a replacement.

</div>

## Description

A <span class="title-ref">RecordSet</span> provides a way to access a group of `Database</api/databases/database>` records (or rows) from a query. Use the methods and properties of the <span class="title-ref">RecordSet</span> class to navigate among this set of records and view, edit, delete, and update individual records.

## Properties

<div class="rst-class">

table-centered_columns_3_and_4

</div>

| Name                               | Type                               | Read-Only | Shared |
|------------------------------------|------------------------------------|-----------|--------|
| `BOF<recordset.bof>`               | `Boolean</api/data_types/boolean>` | ✓         |        |
| `EOF<recordset.eof>`               | `Boolean</api/data_types/boolean>` | ✓         |        |
| `FieldCount<recordset.fieldcount>` | `Integer</api/data_types/integer>` | ✓         |        |

## Methods

<div class="rst-class">

table-centered_column_4

</div>

| Name                                   | Parameters                                  | Returns                                         | Shared |
|----------------------------------------|---------------------------------------------|-------------------------------------------------|--------|
| `Close<recordset.close>`               |                                             |                                                 |        |
| `ColumnType<recordset.columntype>`     | Index As `Integer</api/data_types/integer>` | `Integer</api/data_types/integer>`              |        |
| `DeleteRecord<recordset.deleterecord>` |                                             |                                                 |        |
| `Edit<recordset.edit>`                 |                                             |                                                 |        |
| `Field<recordset.field>`               | Name As `String</api/data_types/string>`    | `DatabaseColumn</api/databases/databasecolumn>` |        |
| `IdxField<recordset.idxfield>`         | Index As `Integer</api/data_types/integer>` | `DatabaseColumn</api/databases/databasecolumn>` |        |
| `MoveFirst<recordset.movefirst>`       |                                             |                                                 |        |
| `MoveLast<recordset.movelast>`         |                                             |                                                 |        |
| `MoveNext<recordset.movenext>`         |                                             |                                                 |        |
| `MovePrevious<recordset.moveprevious>` |                                             |                                                 |        |
| `RecordCount<recordset.recordcount>`   |                                             | `Integer</api/data_types/integer>`              |        |
| `Update<recordset.update>`             |                                             |                                                 |        |

## Property descriptions

<div id="recordset.bof">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

RecordSet.BOF

**BOF** As `Boolean</api/data_types/boolean>`

Returns `True</api/language/true>` when the <span class="title-ref">RecordSet</span> is before the first row or the <span class="title-ref">RecordSet</span> is empty.

This property is read-only.

A new <span class="title-ref">RecordSet</span> is always at the first row (if any rows were returned). The only way to set the <span class="title-ref">RecordSet</span> to be before the first row is to use `RowSet<rowset.movetopreviousrow>`, which is not supported by all data sources.

This moves the <span class="title-ref">RecordSet</span> pointer so that BOF is True:

``` xojo
Dim rs As RecordSet
rs = db.SQLSelect("SELECT * FROM data")
If rs <> Nil Then
  rs.MovePrevious
  If rs.BOF Then MsgBox("BOF!")
End If
```

<div id="recordset.eof">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

RecordSet.EOF

**EOF** As `Boolean</api/data_types/boolean>`

`True</api/language/true>` when the record pointer is at the end of the set of records.

This property is read-only.

The following method populates a `ListBox</api/deprecated/listbox>` with a \`RecordSet\`:

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

  ' set up listbox state for population
  dataList.DeleteAllRows
  dataList.Columncount = rs.Fieldcount

    ' Add the DB columns as the heades 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
```

<div id="recordset.fieldcount">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

RecordSet.FieldCount

**FieldCount** As `Integer</api/data_types/integer>`

The number of fields in the <span class="title-ref">RecordSet</span>.

This property is read-only.

The following method populates a `ListBox</api/deprecated/listbox>` with a <span class="title-ref">RecordSet</span>. Is uses FieldCount to create the header for the ListBox with the names of the columns in the table:

``` xojo
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
```

## Method descriptions

<div id="recordset.close">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

RecordSet.Close

**Close**

Closes an open <span class="title-ref">RecordSet</span>.

When the <span class="title-ref">RecordSet</span> goes out of scope, it is automatically closed.

If you try to use a <span class="title-ref">RecordSet</span> after it has been closed, an `UnsupportedOperationException</api/exceptions/unsupportedoperationexception>` is raised.

The following method populates a `ListBox</api/deprecated/listbox>` with a <span class="title-ref">RecordSet</span> and closes the <span class="title-ref">RecordSet</span> when finished:

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

    ' set up listbox state for population
    dataList.DeleteAllRows
    dataList.Columncount = rs.Fieldcount

    ' Add the DB columns as the heades 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
    rs.Close
End Sub
```

<div id="recordset.columntype">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

RecordSet.ColumnType

**ColumnType**(Index As `Integer</api/data_types/integer>`) As `Integer</api/data_types/integer>`

Returns an integer value for the data type of the passed column. The *index* parameter is 0-based.

The following gets the columntype of the *i*th column in an existing <span class="title-ref">RecordSet</span>.

``` xojo
Dim colType As Integer
Dim stringValue As String

For i As Integer = 0 To rs.FieldCount - 1
  colType = rs.ColumnType(i) ' ColumnType is 0-based
  If colType = 5 Or colType = 18 Then ' The column is a String
     stringValue = rs.IdxField(i + 1).StringValue ' IdxField is 1-based
  End If
Next
```

<div id="recordset.deleterecord">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

RecordSet.DeleteRecord

**DeleteRecord**

Deletes the current record in the <span class="title-ref">RecordSet</span>.

``` xojo
' Delete the current record in an existing RecordSet
' db is an existing database connection
rs.DeleteRecord
If db.Error Then
  MsgBox("DB Error: " + db.ErrorMessage)
End If 
```

<div id="recordset.edit">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

RecordSet.Edit

**Edit**

Call Edit prior to performing modifications to the current record. Be sure the SQL incudes the primary key column (or columns) so that you can update the table after making changes. Changes are only saved to the DB when Update is called.

Set the string value of a column in a \`RecordSet\`:

``` xojo
' rs is a RecordSet with a string column called "ProductName":
rs.Edit
If Not db.Error Then
  rs.Field("ProductName").StringValue = "Generic Widgets"
  rs.Update
  If db.Error Then
    MsgBox("DB Error: " + db.ErrorMessage)
  End If
Else
  MsgBox("DB Error: " + db.ErrorMessage)
End If
```

<div id="recordset.field">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

RecordSet.Field

**Field**(Name As `String</api/data_types/string>`) As `DatabaseColumn</api/databases/databasecolumn>`

Returns a `DatabaseColumn</api/databases/databasecolumn>` containing information about the column (specified by *Name*) from the current position in the <span class="title-ref">RecordSet</span>.

Get the string value of a column in a \`RecordSet\`:

``` xojo
' rs is a RecordSet with a string column called "ProductName"
Dim productName As String
productName = rs.Field("ProductName").StringValue
```

Set the string value of a column in a \`RecordSet\`:

``` xojo
' rs is a RecordSet with a string column called "ProductName":
rs.Edit
rs.Field("ProductName").StringValue = "Generic Widgets"
rs.Update
```

<div id="recordset.idxfield">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

RecordSet.IdxField

**IdxField**(Index As `Integer</api/data_types/integer>`) As `DatabaseColumn</api/databases/databasecolumn>`

Returns a `DatabaseColumn</api/databases/databasecolumn>` containing information about the column (specified by *index*, which is 1-based) from the current position in the <span class="title-ref">RecordSet</span>.

If the <span class="title-ref">RecordSet</span> has no rows, the returned DatabaseField only contains the Name of the column.

<div class="note">

<div class="title">

Note

</div>

The IdxField method is 1-based, not 0-based.

</div>

Get the string value of a column in a \`RecordSet\`:

``` xojo
' rs is a RecordSet; column 1 (the first column) is a string column
Dim productName As String
productName = rs.IdxField(1).StringValue
```

Changes the string value of a column in a \`RecordSet\`:

``` xojo
' rs is a RecordSet; column 1 (the first column) is a string column
rs.Edit
rs.IdxField(1).StringValue = "Generic Widgets"
rs.Update
```

<div id="recordset.movefirst">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

RecordSet.MoveFirst

**MoveFirst**

Moves the record pointer to the first record in the <span class="title-ref">RecordSet</span>.

Currently only supported by these databases: \* `SQLiteDatabase</api/databases/sqlitedatabase>` \* `ODBCDatabase</api/databases/odbcdatabase>`, although not all ODBC drivers implement this

This example moves the record pointer to the first record in the <span class="title-ref">RecordSet</span>.

``` xojo
' move to the first record
rs.MoveFirst
```

<div id="recordset.movelast">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

RecordSet.MoveLast

**MoveLast**

Moves the record pointer to the last record in the <span class="title-ref">RecordSet</span>.

Currently only supported by these databases: \* `SQLiteDatabase</api/databases/sqlitedatabase>` \* `ODBCDatabase</api/databases/odbcdatabase>`, although not all ODBC drivers implement this

This example moves the record pointer to the first record in the <span class="title-ref">RecordSet</span>.

``` xojo
' move to the last record
rs.MoveLast
```

<div id="recordset.movenext">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

RecordSet.MoveNext

**MoveNext**

Moves to the next record/row in the <span class="title-ref">RecordSet</span>. After the last row, `RowSet<rowset.afterlastrow>` is True.

The following method populates a `ListBox</api/deprecated/listbox>` with a <span class="title-ref">RecordSet</span>. It uses the Name and StringValue properties to obtain the fieldnames and values:

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

    ' set up listbox state for population
    dataList.DeleteAllRows
    dataList.Columncount = rs.Fieldcount

    ' Add the DB columns as the heades 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
    rs.Close
End Sub
```

<div id="recordset.moveprevious">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

RecordSet.MovePrevious

**MovePrevious**

Moves the record pointer to the previous record in the <span class="title-ref">RecordSet</span>.

Currently only supported by these databases: \* `SQLiteDatabase</api/databases/sqlitedatabase>` \* `ODBCDatabase</api/databases/odbcdatabase>`, although not all ODBC drivers implement this

A <span class="title-ref">RecordSet</span> is populated in memory when you call the `SQLSelect<database.selectsql>` method. If you use MovePrevious to go back to prior records (including those that you may have changed using the `Edit<rowset.editrow>` method), then you will get the values that were originally populated, not the changed values.

This example moves the record pointer to the previous record in the <span class="title-ref">RecordSet</span>.

``` xojo
' move to the previous record/row
rs.MovePrevious
```

<div id="recordset.recordcount">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

RecordSet.RecordCount

**RecordCount** As `Integer</api/data_types/integer>`

The number of records in the <span class="title-ref">RecordSet</span>.

Currently only supported by these databases: \* `SQLiteDatabase</api/databases/sqlitedatabase>` \* `PostgreSQLDatabase</api/databases/postgresqldatabase>` \* `ODBCDatabase</api/databases/odbcdatabase>`, although not all ODBC drivers implement this

For databases that do not support this function, RecordCount returns -1.

The following method populates a `ListBox</api/deprecated/listbox>` with a <span class="title-ref">RecordSet</span>, first displaying the record count if it can:

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

    ' set up listbox state for population
    dataList.DeleteAllRows
    dataList.Columncount = rs.Fieldcount

    ' Add the DB columns as the heades 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
    rs.Close
End Sub
```

<div id="recordset.update">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

RecordSet.Update

**Update**

Call to update the <span class="title-ref">RecordSet</span> to reflect changes to the record the record pointer is pointing to.

Set the string value of a column in a \`RecordSet\`:

``` xojo
' rs is a RecordSet with a string column called "ProductName":
rs.Edit
If Not db.Error Then
  rs.Field("ProductName").StringValue = "Generic Widgets"
  rs.Update
  If db.Error Then
    MsgBox("DB Error: " + db.ErrorMessage)
  End If
Else
  MsgBox("DB Error: " + db.ErrorMessage)
End If
```

## Notes

If you are creating an application as a front-end in a multi-user environment, keep in mind the following. The `Edit<rowset.editrow>` method will attempt to lock the current record to other users. If a user tries to access a locked record, the `Database</api/databases/database>` class `Error</api/exceptions/databaseexception>` property will return `True</api/language/true>`.

A <span class="title-ref">RecordSet</span> is closed when it goes out of scope.

If you try to use a <span class="title-ref">RecordSet</span> after it has been closed, an `UnsupportedOperationException</api/exceptions/unsupportedoperationexception>` is raised.

The `MoveNext<rowset.movetonextrow>` method unlocks the current record if you previously locked it with the `Edit<rowset.editrow>` method. Previously locked records are also unlocked by the `Close<rowset.close>` method of the class and the `Close<database.close>` method of the `Database</api/databases/database>` class.

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

### Record navigation

Not all data sources support all four record navigation methods, MoveFirst, MoveNext, MovePrevious, MoveLast. The limitations of some of the data sources are presented in the following table.

| Data Source    | Limitation                             |
|----------------|----------------------------------------|
| SQLiteDatabase | Supports all record navigation methods |
| Oracle         | Supports all record navigation methods |
| ODBC           | Supports all record navigation methods |
| mySQL          | Supports only MoveNext method          |
| MS SQL Server  | Supports only MoveNext method          |
| PostgreSQL     | Supports only MoveNext method          |

## Sample code

This code gets the data from the Team table and displays it in a ListBox:

``` xojo
' mDB is a previously connected database

Dim sql As String
sql = "SELECT * FROM Team"

Dim data As RecordSet
data = mDB.SQLSelect(sql)

If mDB.Error Then
  MsgBox("DB Error: " + mDB.ErrorMessage)
  Return
End If

If data <> Nil Then
  While Not data.EOF
    DataList.AddRow(data.IdxField(1).StringValue, data.IdxField(2).StringValue, _
    data.IdxField(3).StringValue, data.IdxField(4).StringValue)

    data.MoveNext
  Wend
  data.Close
End If
```

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

The following method populates a `ListBox</api/deprecated/listbox>` with a <span class="title-ref">RecordSet</span>. It uses the Name and StringValue properties to obtain the fieldnames and values:

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

  ' remove all rows
  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
```

## Compatibility

All project types on all supported operating systems.

## See also

`Object</api/data_types/additional_types/object>` parent class; `Database</api/databases/database>`, `DatabaseColumn</api/databases/databasecolumn>`, `DatabaseRow</api/databases/databaserow>`, `ODBCDatabase</api/databases/odbcdatabase>`, `PostgreSQLDatabase</api/databases/postgresqldatabase>`, `SQLiteDatabase</api/databases/sqlitedatabase>` classes.
