Export (0) Print
Expand All

DataRowCollection Class

Represents a collection of rows for a DataTable.

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

'Declaration
Public NotInheritable Class DataRowCollection _
	Inherits InternalDataCollectionBase

The DataRowCollection type exposes the following members.

  NameDescription
Public propertySupported by the XNA FrameworkCountGets the total number of DataRow objects in this collection. (Overrides InternalDataCollectionBase.Count.)
Public propertySupported by the XNA FrameworkIsReadOnlyGets a value that indicates whether the InternalDataCollectionBase is read-only. (Inherited from InternalDataCollectionBase.)
Public propertySupported by the XNA FrameworkIsSynchronizedGets a value that indicates whether the InternalDataCollectionBase is synchonized. (Inherited from InternalDataCollectionBase.)
Public propertySupported by the XNA FrameworkItemGets the row at the specified index.
Public propertySupported by the XNA FrameworkSyncRootGets an object that can be used to synchronize the collection. (Inherited from InternalDataCollectionBase.)
Top

  NameDescription
Public methodSupported by the XNA FrameworkAdd(DataRow)Adds the specified DataRow to the DataRowCollection object.
Public methodSupported by the XNA FrameworkAdd(Object())Creates a row using specified values and adds it to the DataRowCollection.
Public methodSupported by the XNA FrameworkClearClears the collection of all rows.
Public methodSupported by the XNA FrameworkContains(Object)Gets a value that indicates whether the primary key of any row in the collection contains the specified value.
Public methodSupported by the XNA FrameworkContains(Object())Gets a value that indicates whether the primary key columns of any row in the collection contain the values specified in the object array.
Public methodSupported by the XNA FrameworkCopyTo(Array, Int32)Copies all the DataRow objects from the collection into the given array, starting at the given destination array index. (Overrides InternalDataCollectionBase.CopyTo(Array, Int32).)
Public methodSupported by the XNA FrameworkCopyTo(DataRow(), Int32)Copies all the DataRow objects from the collection into the given array, starting at the given destination array index.
Public methodSupported by the XNA FrameworkEquals(Object)Determines whether the specified object is equal to the current object. (Inherited from Object.)
Public methodSupported by the XNA FrameworkFind(Object)Gets the row specified by the primary key value.
Public methodSupported by the XNA FrameworkFind(Object())Gets the row that contains the specified primary key values.
Public methodSupported by the XNA FrameworkGetEnumeratorGets an IEnumerator for this collection. (Overrides InternalDataCollectionBase.GetEnumerator.)
Public methodSupported by the XNA FrameworkGetHashCodeServes as the default hash function. (Inherited from Object.)
Public methodSupported by the XNA FrameworkGetTypeGets the Type of the current instance. (Inherited from Object.)
Public methodSupported by the XNA FrameworkIndexOfGets the index of the specified DataRow object.
Public methodSupported by the XNA FrameworkInsertAtInserts a new row into the collection at the specified location.
Public methodSupported by the XNA FrameworkRemoveRemoves the specified DataRow from the collection.
Public methodSupported by the XNA FrameworkRemoveAtRemoves the row at the specified index from the collection.
Public methodSupported by the XNA FrameworkToStringReturns a string that represents the current object. (Inherited from Object.)
Top

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.

For other operations, such as sorting or filtering the DataRowCollection, use methods on the DataRowCollection’s associated DataTable.

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.
    Console.WriteLine(table.Rows.Count)

    Dim row  As DataRow
    ' Print the value of columns 1 in each row 
    For Each row In table.Rows
        Console.WriteLine(row(1))
    Next 
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.
    table.Rows.Add(newRow)
End Sub

.NET Framework

Supported in: 4.5.2, 4.5.1, 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

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

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

Show:
© 2014 Microsoft