DataRowCollection Class

 

Represents a collection of rows for a DataTable.

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


public sealed class DataRowCollection : InternalDataCollectionBase

NameDescription
System_CAPS_pubpropertyCount

Gets the total number of DataRow objects in this collection.(Overrides InternalDataCollectionBase.Count.)

System_CAPS_pubpropertyIsReadOnly

Gets a value that indicates whether the InternalDataCollectionBase is read-only.(Inherited from InternalDataCollectionBase.)

System_CAPS_pubpropertyIsSynchronized

Gets a value that indicates whether the InternalDataCollectionBase is synchonized.(Inherited from InternalDataCollectionBase.)

System_CAPS_pubpropertyItem[Int32]

Gets the row at the specified index.

System_CAPS_pubpropertySyncRoot

Gets an object that can be used to synchronize the collection.(Inherited from InternalDataCollectionBase.)

NameDescription
System_CAPS_pubmethodAdd(DataRow)

Adds the specified DataRow to the DataRowCollection object.

System_CAPS_pubmethodAdd(Object[])

Creates a row using specified values and adds it to the DataRowCollection.

System_CAPS_pubmethodClear()

Clears the collection of all rows.

System_CAPS_pubmethodContains(Object)

Gets a value that indicates whether the primary key of any row in the collection contains the specified value.

System_CAPS_pubmethodContains(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.

System_CAPS_pubmethodCopyTo(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).)

System_CAPS_pubmethodCopyTo(DataRow[], Int32)

Copies all the DataRow objects from the collection into the given array, starting at the given destination array index.

System_CAPS_pubmethodEquals(Object)

Determines whether the specified object is equal to the current object.(Inherited from Object.)

System_CAPS_pubmethodFind(Object)

Gets the row specified by the primary key value.

System_CAPS_pubmethodFind(Object[])

Gets the row that contains the specified primary key values.

System_CAPS_pubmethodGetEnumerator()

Gets an IEnumerator for this collection.(Overrides InternalDataCollectionBase.GetEnumerator().)

System_CAPS_pubmethodGetHashCode()

Serves as the default hash function. (Inherited from Object.)

System_CAPS_pubmethodGetType()

Gets the Type of the current instance.(Inherited from Object.)

System_CAPS_pubmethodIndexOf(DataRow)

Gets the index of the specified DataRow object.

System_CAPS_pubmethodInsertAt(DataRow, Int32)

Inserts a new row into the collection at the specified location.

System_CAPS_pubmethodRemove(DataRow)

Removes the specified DataRow from the collection.

System_CAPS_pubmethodRemoveAt(Int32)

Removes the row at the specified index from the collection.

System_CAPS_pubmethodToString()

Returns a string that represents the current object.(Inherited from Object.)

NameDescription
System_CAPS_pubmethodAsParallel()

Overloaded. Enables parallelization of a query.(Defined by ParallelEnumerable.)

System_CAPS_pubmethodAsQueryable()

Overloaded. Converts an IEnumerable to an IQueryable.(Defined by Queryable.)

System_CAPS_pubmethodCast<TResult>()

Casts the elements of an IEnumerable to the specified type.(Defined by Enumerable.)

System_CAPS_pubmethodOfType<TResult>()

Filters the elements of an IEnumerable based on a specified type.(Defined by Enumerable.)

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 void ShowRows(DataTable table)
{
    // Print the number of rows in the collection.
    Console.WriteLine(table.Rows.Count);
    // Print the value of columns 1 in each row
    foreach(DataRow row in table.Rows)
    {
        Console.WriteLine(row[1]);
    }
}

private void AddRow(DataTable table)
{
    DataRowCollection rowCollection = table.Rows;
    // Instantiate a new row using the NewRow method.

    DataRow newRow = table.NewRow();
    // Insert code to fill the row with values.

    // Add the row to the DataRowCollection.
    table.Rows.Add(newRow);
}

.NET Framework
Available since 1.1

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

Return to top
Show: