DataRowCollection Class

Definition

表示 DataTable 的行的集合。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
Public NotInheritable Class DataRowCollection
Inherits InternalDataCollectionBase
Public Class DataRowCollection
Inherits InternalDataCollectionBase
Inheritance
Attributes

Examples

本部分中的第一个示例将打印 DataRowCollection中每一行的列1的值。The first example in this section prints the value of column 1 for every row in a DataRowCollection. 第二个示例使用 NewRow 方法将一个新行添加到 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

DataRowCollectionDataTable的主要组件。The DataRowCollection is a major component of the DataTable. 尽管 DataColumnCollection 定义表的架构,但 DataRowCollection 包含表的实际数据,其中每个 DataRow DataRowCollection 表示单个行。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.

可以调用 AddRemove 方法,以便在 DataRowCollection中插入和删除 DataRow 对象。You can call the Add and Remove methods to insert and delete DataRow objects from the DataRowCollection. 你还可以调用 Find 方法来搜索包含主键列中的特定值的 DataRow 对象,以及用于在基于字符的数据中搜索单个词或短语的 Contains 方法。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.

对于其他操作,如对 DataRowCollection进行排序或筛选,请使用 DataRowCollection相关 DataTable上的方法。For other operations, such as sorting or filtering the DataRowCollection, use methods on the DataRowCollection's associated DataTable.

Properties

Count

获取该集合中 DataRow 对象的总数。Gets the total number of DataRow objects in this collection.

Count

获取集合中的元素总数。Gets the total number of elements in a collection.

(Inherited from InternalDataCollectionBase)
IsReadOnly

获取一个值,该值指示 InternalDataCollectionBase 是否为只读的。Gets a value that indicates whether the InternalDataCollectionBase is read-only.

(Inherited from InternalDataCollectionBase)
IsSynchronized

获取一个值,该值指示 InternalDataCollectionBase 是否已同步。Gets a value that indicates whether the InternalDataCollectionBase is synchronized.

(Inherited from InternalDataCollectionBase)
Item[Int32]

获取指定索引处的行。Gets the row at the specified index.

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)

将指定的 DataRow 添加到 DataRowCollection 对象中。Adds the specified DataRow to the DataRowCollection object.

Add(Object[])

创建使用指定值的行,并将其添加到 DataRowCollection 中。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)

将该集合中的所有 DataRow 对象复制到起始位置为给定目标数组索引的给定数组中。Copies all the DataRow objects from the collection into the given array, starting at the given destination array index.

CopyTo(Array, Int32)

将当前 InternalDataCollectionBase 的所有元素复制到一维 Array,从指定的 InternalDataCollectionBase 索引开始。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)

将该集合中的所有 DataRow 对象复制到起始位置为给定目标数组索引的给定数组中。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()

获取该集合的 IEnumeratorGets an IEnumerator for this collection.

GetEnumerator()

获取集合的 IEnumeratorGets an IEnumerator for the collection.

(Inherited from InternalDataCollectionBase)
GetHashCode()

作为默认哈希函数。Serves as the default hash function.

(Inherited from Object)
GetType()

获取当前实例的 TypeGets the Type of the current instance.

(Inherited from Object)
IndexOf(DataRow)

获取指定 DataRow 对象的索引。Gets the index of the specified DataRow object.

InsertAt(DataRow, Int32)

将新行插入到集合中的指定位置。Inserts a new row into the collection at the specified location.

MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(Inherited from Object)
Remove(DataRow)

从集合中删除指定的 DataRowRemoves 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)

IEnumerable 的元素强制转换为指定的类型。Casts the elements of an IEnumerable to the specified type.

OfType<TResult>(IEnumerable)

根据指定类型筛选 IEnumerable 的元素。Filters the elements of an IEnumerable based on a specified type.

AsParallel(IEnumerable)

启用查询的并行化。Enables parallelization of a query.

AsQueryable(IEnumerable)

IEnumerable 转换为 IQueryableConverts 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