DataTableCollection Classe

Definição

Representa a coleção de tabelas para o DataSet.Represents the collection of tables for the 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
Herança
DataTableCollection
Atributos

Exemplos

O primeiro procedimento neste exemplo recupera o DataTableCollection de a DataSet e imprime o valor de cada coluna, em cada linha, de cada tabela.The first procedure in this example retrieves the DataTableCollection of a DataSet and prints the value of each column, in each row, of each table. O segundo procedimento cria um novo DataTable com duas colunas e a adiciona ao DataTableCollection .The second procedure creates a new DataTable with two columns, and adds it to the 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

Comentários

O DataTableCollection contém todos os DataTable objetos para um específico DataSet .The DataTableCollection contains all the DataTable objects for a particular DataSet. Para acessar o DataTableCollection de a DataSet , use a Tables propriedade.To access the DataTableCollection of a DataSet, use the Tables property.

O DataTableCollection usa métodos como Add , Clear e Remove para gerenciar os itens na coleção.The DataTableCollection uses methods such as Add, Clear, and Remove to manage the items in the collection.

Use o Contains método para determinar se uma determinada tabela (especificada pelo índice ou pelo nome) está na coleção.Use the Contains method to determine whether a particular table (specified by either index or name) is in the collection.

Para navegar de uma tabela para outra, use a ChildRelations ParentRelations propriedade ou do DataTable para acessar sua coleção de DataRelation objetos.To navigate from one table to another, use the ChildRelations or ParentRelations property of the DataTable to access its collection of DataRelation objects. Você também pode usar a Relations propriedade para navegar pelas relações pai/filho de DataTables em uma determinada DataSet coleção.You can also use the Relations property to navigate through the parent/child relationships of the DataTables in a particular DataSet collection.

Propriedades

Count

Obtém o número total de elementos em uma coleção.Gets the total number of elements in a collection.

(Herdado de InternalDataCollectionBase)
IsReadOnly

Obtém um valor que indica se o InternalDataCollectionBase é somente leitura.Gets a value that indicates whether the InternalDataCollectionBase is read-only.

(Herdado de InternalDataCollectionBase)
IsSynchronized

Obtém um valor que indica se o InternalDataCollectionBase é sincronizado.Gets a value that indicates whether the InternalDataCollectionBase is synchronized.

(Herdado de InternalDataCollectionBase)
Item[Int32]

Obtém o objeto DataTable no índice especificado.Gets the DataTable object at the specified index.

Item[String, String]

Obtém o objeto DataTable com o nome especificado no namespace especificado.Gets the DataTable object with the specified name in the specified namespace.

Item[String]

Obtém o objeto DataTable com o nome especificado.Gets the DataTable object with the specified name.

List

Obtém os itens da coleção como uma lista.Gets the items of the collection as a list.

List

Obtém os itens da coleção como uma lista.Gets the items of the collection as a list.

(Herdado de InternalDataCollectionBase)
SyncRoot

Obtém um objeto que pode ser usado para sincronizar a coleção.Gets an object that can be used to synchronize the collection.

(Herdado de InternalDataCollectionBase)

Métodos

Add()

Cria um novo objeto DataTable usando um nome padrão e o adiciona à coleção.Creates a new DataTable object by using a default name and adds it to the collection.

Add(DataTable)

Adiciona o DataTable especificado à coleção.Adds the specified DataTable to the collection.

Add(String)

Cria um objeto DataTable usando o nome especificado e o adiciona à coleção.Creates a DataTable object by using the specified name and adds it to the collection.

Add(String, String)

Cria um objeto DataTable usando o nome especificado e o adiciona à coleção.Creates a DataTable object by using the specified name and adds it to the collection.

AddRange(DataTable[])

Copia os elementos da matriz DataTable especificada para o fim da coleção.Copies the elements of the specified DataTable array to the end of the collection.

CanRemove(DataTable)

Verifica se o objeto DataTable especificado pode ser removido da coleção.Verifies whether the specified DataTable object can be removed from the collection.

Clear()

Limpa a coleção de todos os objetos DataTable.Clears the collection of all DataTable objects.

Contains(String)

Obtém um valor que indica se um objeto DataTable com o nome especificado existe na coleção.Gets a value that indicates whether a DataTable object with the specified name exists in the collection.

Contains(String, String)

Obtém um valor que indica se um objeto DataTable com o nome e o namespace de tabela especificados existe na coleção.Gets a value that indicates whether a DataTable object with the specified name and table namespace exists in the collection.

CopyTo(Array, Int32)

Copia todos os elementos do InternalDataCollectionBase atual para um Array unidimensional, começando no índice InternalDataCollectionBase especificado.Copies all the elements of the current InternalDataCollectionBase to a one-dimensional Array, starting at the specified InternalDataCollectionBase index.

(Herdado de InternalDataCollectionBase)
CopyTo(DataTable[], Int32)

Copia todos os elementos do DataTableCollection atual para um Array unidimensional, começando no índice da matriz de destino especificado.Copies all the elements of the current DataTableCollection to a one-dimensional Array, starting at the specified destination array index.

Equals(Object)

Determina se o objeto especificado é igual ao objeto atual.Determines whether the specified object is equal to the current object.

(Herdado de Object)
GetEnumerator()

Obtém um IEnumerator para a coleção.Gets an IEnumerator for the collection.

(Herdado de InternalDataCollectionBase)
GetHashCode()

Serve como a função de hash padrão.Serves as the default hash function.

(Herdado de Object)
GetType()

Obtém o Type da instância atual.Gets the Type of the current instance.

(Herdado de Object)
IndexOf(DataTable)

Obtém o índice do objeto DataTable especificado.Gets the index of the specified DataTable object.

IndexOf(String)

Obtém o índice na coleção do objeto DataTable com o nome especificado.Gets the index in the collection of the DataTable object with the specified name.

IndexOf(String, String)

Obtém o índice na coleção do objeto DataTable especificado.Gets the index in the collection of the specified DataTable object.

MemberwiseClone()

Cria uma cópia superficial do Object atual.Creates a shallow copy of the current Object.

(Herdado de Object)
OnCollectionChanged(CollectionChangeEventArgs)

Aciona o evento OnCollectionChanged(CollectionChangeEventArgs).Raises the OnCollectionChanged(CollectionChangeEventArgs) event.

OnCollectionChanging(CollectionChangeEventArgs)
Remove(DataTable)

Remove o objeto DataTable especificado da coleção.Removes the specified DataTable object from the collection.

Remove(String)

Remove o objeto DataTable com o nome especificado da coleção.Removes the DataTable object with the specified name from the collection.

Remove(String, String)

Remove o objeto DataTable com o nome especificado da coleção.Removes the DataTable object with the specified name from the collection.

RemoveAt(Int32)

Remove o objeto DataTable no índice especificado da coleção.Removes the DataTable object at the specified index from the collection.

ToString()

Retorna uma cadeia de caracteres que representa o objeto atual.Returns a string that represents the current object.

(Herdado de Object)

Eventos

CollectionChanged

Ocorre após o DataTableCollection ser alterado devido aos objetos DataTable sendo adicionados ou removidos.Occurs after the DataTableCollection is changed because of DataTable objects being added or removed.

CollectionChanging

Ocorre enquanto o DataTableCollection está sendo alterado devido aos objetos DataTable sendo adicionados ou removidos.Occurs while the DataTableCollection is changing because of DataTable objects being added or removed.

Métodos de Extensão

Cast<TResult>(IEnumerable)

Converte os elementos de um IEnumerable para o tipo especificado.Casts the elements of an IEnumerable to the specified type.

OfType<TResult>(IEnumerable)

Filtra os elementos de um IEnumerable com base em um tipo especificado.Filters the elements of an IEnumerable based on a specified type.

AsParallel(IEnumerable)

Habilita a paralelização de uma consulta.Enables parallelization of a query.

AsQueryable(IEnumerable)

Converte um IEnumerable em um IQueryable.Converts an IEnumerable to an IQueryable.

Aplica-se a

Acesso thread-safe

Este tipo é seguro para operações de leitura e multithread.This type is safe for multithreaded read operations. Você deve sincronizar todas as operações de gravação.You must synchronize any write operations.

Confira também