' Set PrimaryKey
customerTable.Columns("id").Unique = True
customerTable.PrimaryKey = New DataColumn() _
{customerTable.Columns("id")}
' add ten rows
Dim id As Integer
For id = 1 To 10
customerTable.Rows.Add( _
New Object() {id, String.Format("customer{0}", id)})
Next id
customerTable.AcceptChanges()
' add another ten rows
For id = 11 To 20
customerTable.Rows.Add( _
New Object() {id, String.Format("customer{0}", id)})
Next id
' Use the Select method to find all rows matching the filter.
Dim foundRows As DataRow() = _
customerTable.Select(expression, sortOrder, _
DataViewRowState.Added)
PrintRows(foundRows, "filtered rows")
foundRows = customerTable.Select()
PrintRows(foundRows, "all rows")
End Sub
Private Sub PrintRows(ByVal rows() As DataRow, ByVal label As String)
Console.WriteLine("\n{0}", label)
If rows.Length <= 0 Then
Console.WriteLine("no rows found")
Exit Sub
End If
Dim row As DataRow
Dim column As DataColumn
For Each row In rows
For Each column In row.Table.Columns
Console.Write("\table {0}", row(column))
Next column
Console.WriteLine()
Next row
End Sub