DataRowCollection Class
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Represents a collection of rows for a DataTable.
public ref class DataRowCollection sealed : System::Data::InternalDataCollectionBase
public ref class DataRowCollection : System::Data::InternalDataCollectionBase
public sealed class DataRowCollection : System.Data.InternalDataCollectionBase
[System.Serializable]
public class DataRowCollection : System.Data.InternalDataCollectionBase
type DataRowCollection = class
inherit InternalDataCollectionBase
[<System.Serializable>]
type DataRowCollection = class
inherit InternalDataCollectionBase
Public NotInheritable Class DataRowCollection
Inherits InternalDataCollectionBase
Public Class DataRowCollection
Inherits InternalDataCollectionBase
- Inheritance
- Attributes
Examples
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);
}
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
Remarks
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.
Properties
Count |
Gets the total number of DataRow objects in this collection. |
Count |
Gets the total number of elements in a collection. (Inherited from InternalDataCollectionBase) |
IsReadOnly |
Gets a value that indicates whether the InternalDataCollectionBase is read-only. (Inherited from InternalDataCollectionBase) |
IsSynchronized |
Gets a value that indicates whether the InternalDataCollectionBase is synchronized. (Inherited from InternalDataCollectionBase) |
Item[Int32] |
Gets the row at the specified index. |
List | |
List |
Gets the items of the collection as a list. (Inherited from InternalDataCollectionBase) |
SyncRoot |
Gets an object that can be used to synchronize the collection. (Inherited from InternalDataCollectionBase) |
Methods
Add(DataRow) |
Adds the specified DataRow to the DataRowCollection object. |
Add(Object[]) |
Creates a row using specified values and adds it to the DataRowCollection. |
Clear() |
Clears the collection of all rows. |
Contains(Object) |
Gets a value that indicates whether the primary key of any row in the collection contains the specified value. |
Contains(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. |
CopyTo(Array, Int32) |
Copies all the DataRow objects from the collection into the given array, starting at the given destination array index. |
CopyTo(Array, Int32) |
Copies all the elements of the current InternalDataCollectionBase to a one-dimensional Array, starting at the specified InternalDataCollectionBase index. (Inherited from InternalDataCollectionBase) |
CopyTo(DataRow[], Int32) |
Copies all the DataRow objects from the collection into the given array, starting at the given destination array index. |
Equals(Object) |
Determines whether the specified object is equal to the current object. (Inherited from Object) |
Find(Object) |
Gets the row specified by the primary key value. |
Find(Object[]) |
Gets the row that contains the specified primary key values. |
GetEnumerator() |
Gets an IEnumerator for this collection. |
GetEnumerator() |
Gets an IEnumerator for the collection. (Inherited from InternalDataCollectionBase) |
GetHashCode() |
Serves as the default hash function. (Inherited from Object) |
GetType() |
Gets the Type of the current instance. (Inherited from Object) |
IndexOf(DataRow) |
Gets the index of the specified DataRow object. |
InsertAt(DataRow, Int32) |
Inserts a new row into the collection at the specified location. |
MemberwiseClone() |
Creates a shallow copy of the current Object. (Inherited from Object) |
Remove(DataRow) |
Removes the specified DataRow from the collection. |
RemoveAt(Int32) |
Removes the row at the specified index from the collection. |
ToString() |
Returns a string that represents the current object. (Inherited from Object) |
Extension Methods
Cast<TResult>(IEnumerable) |
Casts the elements of an IEnumerable to the specified type. |
OfType<TResult>(IEnumerable) |
Filters the elements of an IEnumerable based on a specified type. |
AsParallel(IEnumerable) |
Enables parallelization of a query. |
AsQueryable(IEnumerable) |
Converts an IEnumerable to an IQueryable. |
Applies to
Thread Safety
This type is safe for multithreaded read operations. You must synchronize any write operations.
See also
Atsauksmes
https://aka.ms/ContentUserFeedback.
Drīzumā: 2024. gada laikā mēs pakāpeniski pārtrauksim izmantot “GitHub problēmas” kā atsauksmju par saturu mehānismu un aizstāsim to ar jaunu atsauksmju sistēmu. Papildinformāciju skatiet:Iesniegt un skatīt atsauksmes par