DataRowCollection DataRowCollection DataRowCollection DataRowCollection Class

定義

表示 DataTable 的資料列集合。Represents a collection of rows for a DataTable.

public ref class DataRowCollection sealed : System::Data::InternalDataCollectionBase
[System.Serializable]
public sealed class DataRowCollection : System.Data.InternalDataCollectionBase
type DataRowCollection = class
    inherit InternalDataCollectionBase
Public NotInheritable Class DataRowCollection
Inherits InternalDataCollectionBase
繼承
屬性

範例

本節中的第一個範例會針對中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

備註

是的主要元件DataTableDataRowCollectionThe DataRowCollection is a major component of the DataTable. 當定義資料表的架構時DataRowCollection ,會包含資料表的實際資料,而中的DataRowCollection每個都DataRow代表一個資料列。 DataColumnCollectionWhile 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.

屬性

Count Count Count Count

取得此集合中的 DataRow 物件總數。Gets the total number of DataRow objects in this collection.

IsReadOnly IsReadOnly IsReadOnly IsReadOnly

取得值,這個值表示 InternalDataCollectionBase 是否為唯讀。Gets a value that indicates whether the InternalDataCollectionBase is read-only.

(Inherited from InternalDataCollectionBase)
IsSynchronized IsSynchronized IsSynchronized IsSynchronized

取得值,表示 InternalDataCollectionBase 是否同步處理。Gets a value that indicates whether the InternalDataCollectionBase is synchronized.

(Inherited from InternalDataCollectionBase)
Item[Int32] Item[Int32] Item[Int32] Item[Int32]

取得在指定索引處的資料列。Gets the row at the specified index.

List List List List

取得集合的項目做為清單。Gets the items of the collection as a list.

(Inherited from InternalDataCollectionBase)
SyncRoot SyncRoot SyncRoot SyncRoot

取得可以用來同步集合的物件。Gets an object that can be used to synchronize the collection.

(Inherited from InternalDataCollectionBase)

方法

Add(DataRow) Add(DataRow) Add(DataRow) Add(DataRow)

將指定的 DataRow 加入至 DataRowCollection 物件中。Adds the specified DataRow to the DataRowCollection object.

Add(Object[]) Add(Object[]) Add(Object[]) Add(Object[])

使用指定的值建立資料列,並將它加入至 DataRowCollectionCreates a row using specified values and adds it to the DataRowCollection.

Clear() Clear() Clear() Clear()

清除所有資料列的集合。Clears the collection of all rows.

Contains(Object) Contains(Object) Contains(Object) Contains(Object)

取得值,指出集合中任何資料列的主索引鍵是否包含指定的值。Gets a value that indicates whether the primary key of any row in the collection contains the specified value.

Contains(Object[]) Contains(Object[]) Contains(Object[]) 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) CopyTo(Array, Int32) CopyTo(Array, Int32) CopyTo(Array, Int32)

將這個集合中所有的 DataRow 物件複製到從指定目的端陣列索引開始的指定陣列中。Copies all the DataRow objects from the collection into the given array, starting at the given destination array index.

CopyTo(DataRow[], Int32) CopyTo(DataRow[], Int32) CopyTo(DataRow[], Int32) 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) Equals(Object) Equals(Object) Equals(Object)

判斷指定的物件是否等於目前的物件。Determines whether the specified object is equal to the current object.

(Inherited from Object)
Find(Object) Find(Object) Find(Object) Find(Object)

取得主索引鍵值指定的資料列。Gets the row specified by the primary key value.

Find(Object[]) Find(Object[]) Find(Object[]) Find(Object[])

取得包含指定主索引鍵值的資料列。Gets the row that contains the specified primary key values.

GetEnumerator() GetEnumerator() GetEnumerator() GetEnumerator()

取得這個集合的 IEnumeratorGets an IEnumerator for this collection.

GetHashCode() GetHashCode() GetHashCode() GetHashCode()

做為預設雜湊函式。Serves as the default hash function.

(Inherited from Object)
GetType() GetType() GetType() GetType()

取得目前執行個體的 TypeGets the Type of the current instance.

(Inherited from Object)
IndexOf(DataRow) IndexOf(DataRow) IndexOf(DataRow) IndexOf(DataRow)

取得指定 DataRow 物件的索引。Gets the index of the specified DataRow object.

InsertAt(DataRow, Int32) InsertAt(DataRow, Int32) InsertAt(DataRow, Int32) InsertAt(DataRow, Int32)

將新的資料列插入集合的指定位置。Inserts a new row into the collection at the specified location.

MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

建立目前 Object 的淺層複本 (Shallow Copy)。Creates a shallow copy of the current Object.

(Inherited from Object)
Remove(DataRow) Remove(DataRow) Remove(DataRow) Remove(DataRow)

從集合移除指定的 DataRowRemoves the specified DataRow from the collection.

RemoveAt(Int32) RemoveAt(Int32) RemoveAt(Int32) RemoveAt(Int32)

從集合的指定索引處移除資料列。Removes the row at the specified index from the collection.

ToString() ToString() ToString() ToString()

傳回代表目前物件的字串。Returns a string that represents the current object.

(Inherited from Object)

擴充方法

Cast<TResult>(IEnumerable) Cast<TResult>(IEnumerable) Cast<TResult>(IEnumerable) Cast<TResult>(IEnumerable)

IEnumerable 的項目轉換成指定的型別。Casts the elements of an IEnumerable to the specified type.

OfType<TResult>(IEnumerable) OfType<TResult>(IEnumerable) OfType<TResult>(IEnumerable) OfType<TResult>(IEnumerable)

根據指定的型別來篩選 IEnumerable 的項目。Filters the elements of an IEnumerable based on a specified type.

AsParallel(IEnumerable) AsParallel(IEnumerable) AsParallel(IEnumerable) AsParallel(IEnumerable)

啟用查詢的平行化作業。Enables parallelization of a query.

AsQueryable(IEnumerable) AsQueryable(IEnumerable) AsQueryable(IEnumerable) AsQueryable(IEnumerable)

IEnumerable 轉換成 IQueryableConverts an IEnumerable to an IQueryable.

適用於

執行緒安全性

這種類型對於多執行緒讀取作業而言是安全的。This type is safe for multithreaded read operations. 您必須同步處理任何寫入作業。You must synchronize any write operations.

另請參閱