DataRowCollection Class

Represents a collection of rows for a DataTable.

Namespace: System.Data
Assembly: System.Data (in

Public NotInheritable Class DataRowCollection
	Inherits InternalDataCollectionBase
Dim instance As DataRowCollection

public final class DataRowCollection extends InternalDataCollectionBase
public final class DataRowCollection extends InternalDataCollectionBase

The DataRowCollection is a major component of the DataTable. While the DataColumnCollection defines the schema of the table, the DataRowCollection contains the actual data for the table, where each DataRow in the DataRowCollection represents a single row.

You can call the Add and Remove methods to insert and delete DataRow objects from the DataRowCollection. You can also call the Find method to search for DataRow objects that contain specific values in primary key columns, and the Contains method to search character-based data for single words or phrases.

The first example in this section prints the value of column 1 for every row in a DataRowCollection. The second example adds a new row created by using the NewRow method to the DataRowCollection.

Private Sub ShowRows(Byval table As DataTable)
    ' Print the number of rows in the collection.

    Dim row  As DataRow
    ' Print the value of columns 1 in each row
    For Each row In table.Rows
End Sub
Private Sub AddRow(ByVal table As DataTable)
    ' Instantiate a new row using the NewRow method.
    Dim newRow As DataRow = table.NewRow()
    ' Insert code to fill the row with values.

    ' Add the row to the DataRowCollection.
End Sub

This type is safe for multithreaded read operations. You must synchronize any write operations.

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0

Community Additions