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
- 继承
- 属性
示例
此示例中的第一个过程检索 DataTableCollection 一个 DataSet 列的值,并打印每个表的每一行的值。 第二个过程创建一个包含两列的新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
注解
包含DataTableCollection特定DataSet对象的所有DataTable对象。 若要访问 DataTableCollection a DataSet,请使用该 Tables 属性。
该方法DataTableCollection使用方法,例如AddClear,并Remove管理集合中的项。
Contains使用该方法确定特定表(由索引或名称指定)是否在集合中。
若要从一个表导航到另一个表,请使用 ChildRelations 该表的或 ParentRelations 属性 DataTable 访问其对象集合 DataRelation 。 还可以使用该Relations属性浏览特定DataSet集合中的父/子关系DataTables。
属性
| 名称 | 说明 |
|---|---|
| Count |
获取集合中的元素总数。 (继承自 InternalDataCollectionBase) |
| IsReadOnly |
获取一个值,该值指示是否 InternalDataCollectionBase 为只读。 (继承自 InternalDataCollectionBase) |
| IsSynchronized |
获取一个值,该值指示是否 InternalDataCollectionBase 同步。 (继承自 InternalDataCollectionBase) |
| Item[Int32] |
DataTable获取指定索引处的对象。 |
| Item[String, String] |
DataTable获取指定命名空间中具有指定名称的对象。 |
| Item[String] |
DataTable获取具有指定名称的对象。 |
| List |
获取作为列表的集合的项。 |
| List |
获取作为列表的集合的项。 (继承自 InternalDataCollectionBase) |
| SyncRoot |
获取可用于同步集合的对象。 (继承自 InternalDataCollectionBase) |
方法
活动
| 名称 | 说明 |
|---|---|
| CollectionChanged |
由于DataTable添加或删除对象而更改后DataTableCollection发生。 |
| CollectionChanging |
DataTableCollection由于添加或删除的对象而DataTable更改时发生。 |
扩展方法
| 名称 | 说明 |
|---|---|
| AsParallel(IEnumerable) |
启用查询的并行化。 |
| AsQueryable(IEnumerable) |
将 IEnumerable 转换为 IQueryable。 |
| Cast<TResult>(IEnumerable) |
将 IEnumerable 的元素强制转换为指定类型。 |
| OfType<TResult>(IEnumerable) |
根据指定类型筛选 IEnumerable 的元素。 |
适用于
线程安全性
此类型对于多线程读取操作是安全的。 必须同步任何写入操作。