DataRowCollection 类

定义

表示 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
继承
属性

示例

本节中的第一个示例打印 中每一行的第 1 列 DataRowCollection的值。 第二个示例使用 NewRow 方法创建的新行添加到 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

注解

DataRowCollection是 的主要组件DataTableDataColumnCollection虽然 定义表的架构, DataRowCollection 但 包含表的实际数据,其中 中的每个 DataRow 代表DataRowCollection一行。

可以调用 AddRemove 方法来插入和删除 DataRow 中的 DataRowCollection对象。 还可以调用 方法来搜索DataRow主键列中包含特定值的对象,并Contains调用 Find 方法搜索基于字符的数据以获取单个单词或短语。

对于其他操作,例如排序或筛选 DataRowCollection,请在 的关联 DataTable上使用DataRowCollection方法。

属性

Count

获取该集合中 DataRow 对象的总数。

Count

获取集合中的元素总数。

(继承自 InternalDataCollectionBase)
IsReadOnly

获取一个值,该值指示 InternalDataCollectionBase 是否为只读。

(继承自 InternalDataCollectionBase)
IsSynchronized

获取一个值,该值指示 InternalDataCollectionBase 是否已同步。

(继承自 InternalDataCollectionBase)
Item[Int32]

获取指定索引处的行。

List

表示 DataTable 的行的集合。

List

获取作为列表的集合的项。

(继承自 InternalDataCollectionBase)
SyncRoot

获取可用于同步集合的对象。

(继承自 InternalDataCollectionBase)

方法

Add(DataRow)

将指定的 DataRow 添加到 DataRowCollection 对象中。

Add(Object[])

创建使用指定值的行,并将其添加到 DataRowCollection 中。

Clear()

清除所有行的集合。

Contains(Object)

获取一个值,该值指示集合中任何行的主键中是否包含指定的值。

Contains(Object[])

获取一个值,该值指示集合中任何行的主键列中是否包含在对象数组中指定的值。

CopyTo(Array, Int32)

将该集合中的所有 DataRow 对象复制到起始位置为给定目标数组索引的给定数组中。

CopyTo(Array, Int32)

将当前 InternalDataCollectionBase 的所有元素复制到一维 Array,从指定的 InternalDataCollectionBase 索引开始。

(继承自 InternalDataCollectionBase)
CopyTo(DataRow[], Int32)

将该集合中的所有 DataRow 对象复制到起始位置为给定目标数组索引的给定数组中。

Equals(Object)

确定指定对象是否等于当前对象。

(继承自 Object)
Find(Object)

获取由主键值指定的行。

Find(Object[])

获取包含指定的主键值的行。

GetEnumerator()

获取该集合的 IEnumerator

GetEnumerator()

获取集合的 IEnumerator

(继承自 InternalDataCollectionBase)
GetHashCode()

作为默认哈希函数。

(继承自 Object)
GetType()

获取当前实例的 Type

(继承自 Object)
IndexOf(DataRow)

获取指定 DataRow 对象的索引。

InsertAt(DataRow, Int32)

将新行插入到集合中的指定位置。

MemberwiseClone()

创建当前 Object 的浅表副本。

(继承自 Object)
Remove(DataRow)

从集合中移除指定的 DataRow

RemoveAt(Int32)

从集合中移除指定索引处的行。

ToString()

返回表示当前对象的字符串。

(继承自 Object)

扩展方法

Cast<TResult>(IEnumerable)

IEnumerable 的元素强制转换为指定的类型。

OfType<TResult>(IEnumerable)

根据指定类型筛选 IEnumerable 的元素。

AsParallel(IEnumerable)

启用查询的并行化。

AsQueryable(IEnumerable)

IEnumerable 转换为 IQueryable

适用于

线程安全性

此类型对于多线程读取操作是安全的。 必须同步所有写入操作。

另请参阅