DataRowCollection Class
Collapse the table of content
Expand the table of content

DataRowCollection Class

Represents a collection of rows for a DataTable.

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

Public NotInheritable Class DataRowCollection _
	Inherits InternalDataCollectionBase
Dim instance As DataRowCollection

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 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98, Windows CE, Windows Mobile for Smartphone, Windows Mobile for Pocket PC, Xbox 360, Zune

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

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 3.5, 2.0, 1.0

XNA Framework

Supported in: 3.0, 2.0, 1.0

Community Additions

© 2016 Microsoft