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
繼承
屬性

範例

本節中的第一個範例會列印 中 DataRowCollection每個數據列的數據行 1 值。 第二個範例會將使用 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。 您也可以呼叫 Find 方法來搜尋 DataRow 主鍵數據行中包含特定值的物件,以及 Contains 搜尋單一單字或片語之字元型數據的方法。

對於其他作業,例如排序或篩選 DataRowCollection,請使用 相關聯 DataTableDataRowCollection的方法。

屬性

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

適用於

執行緒安全性

此類型適用於多線程讀取作業。 您必須同步處理任何寫入作業。

另請參閱