DataTableCollection 類別
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
代表 的 DataSet表格集合。
public ref class DataTableCollection sealed : System::Data::InternalDataCollectionBase
public ref class DataTableCollection : System::Data::InternalDataCollectionBase
[System.ComponentModel.ListBindable(false)]
public sealed class DataTableCollection : System.Data.InternalDataCollectionBase
[System.ComponentModel.ListBindable(false)]
[System.Serializable]
public class DataTableCollection : System.Data.InternalDataCollectionBase
[<System.ComponentModel.ListBindable(false)>]
type DataTableCollection = class
inherit InternalDataCollectionBase
[<System.ComponentModel.ListBindable(false)>]
[<System.Serializable>]
type DataTableCollection = class
inherit InternalDataCollectionBase
Public NotInheritable Class DataTableCollection
Inherits InternalDataCollectionBase
Public Class DataTableCollection
Inherits InternalDataCollectionBase
- 繼承
- 屬性
範例
本範例中的第一個程序是取得 a DataSet 的 ,DataTableCollection並列印每個資料表每一列的值。 第二個程序是建立一個有兩欄的新資料 DataTable ,並將其加入 DataTableCollection。
private void GetTables(DataSet dataSet)
{
// Get Each DataTable in the DataTableCollection and
// print each row value.
foreach (DataTable table in dataSet.Tables)
foreach (DataRow row in table.Rows)
foreach (DataColumn column in table.Columns)
if (row[column] != null)
Console.WriteLine(row[column]);
}
private void CreateTable(DataSet dataSet)
{
DataTable newTable = new DataTable("table");
newTable.Columns.Add("ID", typeof(int));
newTable.Columns.Add("Name", typeof(string));
dataSet.Tables.Add(newTable);
}
Private Sub GetTables(dataSet As DataSet)
' Get Each DataTable in the DataTableCollection and
' print each row value.
Dim table As DataTable
Dim row As DataRow
Dim column As DataColumn
For Each table In dataSet.Tables
For Each row In table.Rows
For Each column in table.Columns
If Not (row(column) Is Nothing) Then
Console.WriteLine(row(column))
End If
Next
Next
Next
End Sub
Private Sub CreateTable(dataSet As DataSet)
Dim newTable As New DataTable("table")
newTable.Columns.Add("ID", Type.GetType("System.Int32"))
newTable.Columns.Add("Name", Type.GetType("System.String"))
dataSet.Tables.Add(newTable)
End Sub
備註
包含DataTableCollectionDataTable特定 DataSet的所有物件。 要存取 DataTableCollectionDataSet,請使用該物業。Tables
該方法 DataTableCollection 使用如 Add、 Clear、 Remove 等方法來管理集合中的項目。
使用此 Contains 方法判斷特定資料表(由索引或名稱指定)是否在集合中。
要從一個資料表移動到另一個資料表,請使用 ChildRelations 的 DataTable 或 ParentRelations 屬性來存取其物件集合DataRelation。 你也可以用這個Relations屬性來瀏覽特定DataSet集合中 的DataTables父子關係。
屬性
| 名稱 | Description |
|---|---|
| Count |
取得集合中元素的總數。 (繼承來源 InternalDataCollectionBase) |
| IsReadOnly |
會得到一個值,表示 是否 InternalDataCollectionBase 為唯讀。 (繼承來源 InternalDataCollectionBase) |
| IsSynchronized |
會得到一個表示是否 InternalDataCollectionBase 同步的值。 (繼承來源 InternalDataCollectionBase) |
| Item[Int32] |
取得 DataTable 指定索引的物件。 |
| Item[String, String] |
取得 DataTable 指定命名空間中擁有指定名稱的物件。 |
| Item[String] |
取得 DataTable 指定名稱的物件。 |
| List |
會把收藏品當成清單。 |
| List |
會把收藏品當成清單。 (繼承來源 InternalDataCollectionBase) |
| SyncRoot |
取得一個可以用來同步集合的物件。 (繼承來源 InternalDataCollectionBase) |
方法
事件
| 名稱 | Description |
|---|---|
| CollectionChanged |
發生在 DataTableCollection 物件被新增 DataTable 或移除後。 |
| CollectionChanging |
發生在物件 DataTableCollection 被 DataTable 新增或移除時。 |
擴充方法
| 名稱 | Description |
|---|---|
| AsParallel(IEnumerable) |
啟用查詢的平行處理。 |
| AsQueryable(IEnumerable) |
將 IEnumerable 轉換成 IQueryable。 |
| Cast<TResult>(IEnumerable) |
將 IEnumerable 的項目轉換成指定的型別。 |
| OfType<TResult>(IEnumerable) |
根據指定的型別篩選 IEnumerable 的專案。 |
適用於
執行緒安全性
此類型適合多執行緒讀取操作。 你必須同步所有寫入操作。