DataRowCollection 类

表示 DataTable 的行的集合。

**命名空间:**System.Data
**程序集:**System.Data(在 system.data.dll 中)

语法

声明
Public NotInheritable Class DataRowCollection
    Inherits InternalDataCollectionBase
用法
Dim instance As DataRowCollection
public sealed class DataRowCollection : InternalDataCollectionBase
public ref class DataRowCollection sealed : public InternalDataCollectionBase
public final class DataRowCollection extends InternalDataCollectionBase
public final class DataRowCollection extends InternalDataCollectionBase

备注

DataRowCollectionDataTable 的主要组件。当 DataColumnCollection 定义表的架构时,DataRowCollection 中包含表的实际数据,在该表中,DataRowCollection 中的每个 DataRow 表示单行。

您可通过调用 AddRemove 方法,从 DataRowCollection 中插入和删除 DataRow 对象。您还可通过调用 Find 方法搜索在主键列中包含特定值的 DataRow 对象,也可通过调用 Contains 方法在基于字符的数据中搜索单个单词或词组。

示例

本节中的第一个示例打印 DataRowCollection 中每一行的第 1 列的值。第二个示例向 DataRowCollection 中添加用 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
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);
}

继承层次结构

System.Object
   System.Data.InternalDataCollectionBase
    System.Data.DataRowCollection

线程安全

该类型对于多线程读操作是安全的。您必须使任何写操作同步。

平台

Windows 98、Windows 2000 SP4、Windows CE、Windows Millennium Edition、Windows Mobile for Pocket PC、Windows Mobile for Smartphone、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter Edition

.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求

版本信息

.NET Framework

受以下版本支持:2.0、1.1、1.0

.NET Compact Framework

受以下版本支持:2.0、1.0

请参见

参考

DataRowCollection 成员
System.Data 命名空间
DataRow 类
DataTable
NewRow