请单击以进行评分并提供反馈
MSDN
MSDN Library
.NET 开发
先前版本
System.Data

  开启低带宽视图
此页面仅适用于
Microsoft Visual Studio 2005/.NET Framework 2.0

同时提供下列产品的其他版本:
.NET Framework 类库
DataRowCollection 类

表示 DataTable 的行的集合。

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

Visual Basic(声明)
Public NotInheritable Class DataRowCollection
    Inherits InternalDataCollectionBase
Visual Basic(用法)
Dim instance As DataRowCollection
C#
public sealed class DataRowCollection : InternalDataCollectionBase
C++
public ref class DataRowCollection sealed : public InternalDataCollectionBase
J#
public final class DataRowCollection extends InternalDataCollectionBase
JScript
public final class DataRowCollection extends InternalDataCollectionBase

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

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

本节中的第一个示例打印 DataRowCollection 中每一行的第 1 列的值。第二个示例向 DataRowCollection 中添加用 NewRow 方法创建的新行。

Visual Basic
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
C#
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
社区内容   什么是社区内容?
添加新内容 RSS  批注
Processing
© 2009 Microsoft Corporation 版权所有。 保留所有权利  |  商标  |  隐私权声明
Page view tracker