DataRowCollection 類別

定義

表示 DataTable 的資料列集合。Represents a collection of rows for a 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的值 DataRowCollectionThe first example in this section prints the value of column 1 for every row in a DataRowCollection. 第二個範例會將使用方法建立的新資料列加入 NewRowDataRowCollectionThe 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

備註

DataRowCollection是的主要元件 DataTableThe DataRowCollection is a major component of the DataTable. DataColumnCollection定義資料表的架構時,會 DataRowCollection 包含資料表的實際資料,其中的每一個都 DataRow DataRowCollection 代表一個資料列。While 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 方法,以插入和刪除 DataRow 中的物件 DataRowCollectionYou 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 DataTableFor other operations, such as sorting or filtering the DataRowCollection, use methods on the DataRowCollection's associated DataTable.

屬性

Count

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

Count

取得集合中的項目總數。Gets the total number of elements in a collection.

(繼承來源 InternalDataCollectionBase)
IsReadOnly

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

(繼承來源 InternalDataCollectionBase)
IsSynchronized

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

(繼承來源 InternalDataCollectionBase)
Item[Int32]

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

List
List

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

(繼承來源 InternalDataCollectionBase)
SyncRoot

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

(繼承來源 InternalDataCollectionBase)

方法

Add(DataRow)

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

Add(Object[])

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

Clear()

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

Contains(Object)

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

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)

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

CopyTo(Array, Int32)

複製目前 InternalDataCollectionBase 的所有項目至一維 Array,開始於指定的 InternalDataCollectionBase 索引。Copies all the elements of the current InternalDataCollectionBase to a one-dimensional Array, starting at the specified InternalDataCollectionBase index.

(繼承來源 InternalDataCollectionBase)
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)

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

(繼承來源 Object)
Find(Object)

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

Find(Object[])

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

GetEnumerator()

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

GetEnumerator()

取得集合的 IEnumeratorGets an IEnumerator for the collection.

(繼承來源 InternalDataCollectionBase)
GetHashCode()

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

(繼承來源 Object)
GetType()

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

(繼承來源 Object)
IndexOf(DataRow)

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

InsertAt(DataRow, Int32)

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

MemberwiseClone()

建立目前 Object 的淺層複製。Creates a shallow copy of the current Object.

(繼承來源 Object)
Remove(DataRow)

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

RemoveAt(Int32)

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

ToString()

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

(繼承來源 Object)

擴充方法

Cast<TResult>(IEnumerable)

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

OfType<TResult>(IEnumerable)

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

AsParallel(IEnumerable)

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

AsQueryable(IEnumerable)

IEnumerable 轉換成 IQueryableConverts an IEnumerable to an IQueryable.

適用於

執行緒安全性

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

另請參閱