DataTableCollection.Contains Método

Definição

Recebe um valor que indica se existe um DataTable objeto com o nome especificado na coleção.

Sobrecargas

Name Description
Contains(String)

Recebe um valor que indica se existe um DataTable objeto com o nome especificado na coleção.

Contains(String, String)

Obtém um valor que indica se existe um DataTable objeto com o nome e o espaço de nomes da tabela especificados na coleção.

Contains(String)

Recebe um valor que indica se existe um DataTable objeto com o nome especificado na coleção.

public:
 bool Contains(System::String ^ name);
public bool Contains(string name);
member this.Contains : string -> bool
Public Function Contains (name As String) As Boolean

Parâmetros

name
String

O nome do DataTable a encontrar.

Devoluções

true se a tabela especificada existir; caso contrário false.

Exemplos

O exemplo seguinte testa se existe uma tabela com o nome "Suppliers" no DataTableCollection.

private void TestForTableName()
{
    // Get the DataSet of a DataGrid.
    DataSet thisDataSet = (DataSet)DataGrid1.DataSource;

    // Get the DataTableCollection through the Tables property.
    DataTableCollection tablesCol = thisDataSet.Tables;

    // Check if the named table exists.
    if (tablesCol.Contains("Suppliers"))
        Console.WriteLine("Table named Suppliers exists");
}
Private Sub TestForTableName()
   ' Get the DataSet of a DataGrid.
   Dim thisDataSet As DataSet = CType(DataGrid1.DataSource, DataSet)

   ' Get the DataTableCollection through the Tables property.
   Dim tablesCol As DataTableCollection = thisDataSet.Tables

   ' Check if the named table exists.
   If tablesCol.Contains("Suppliers") Then 
      Console.WriteLine("Table named Suppliers exists")
   End If
End Sub

Observações

Especifica o nome do DataTable objeto usando a TableName propriedade. Se adicionar a DataTable à coleção com o Add método, sem passar argumentos, a tabela recebe um nome padrão, baseado na ordem em que a tabela foi adicionada ("Table1", "Table2", e assim sucessivamente).

Para obter o índice de um DataTable, use o IndexOf método .

Note

Retorna false quando duas ou mais tabelas têm o mesmo nome mas espaços de nomes diferentes. A chamada não tem sucesso se houver qualquer ambiguidade ao associar um nome de tabela a exatamente uma tabela.

Ver também

Aplica-se a

Contains(String, String)

Obtém um valor que indica se existe um DataTable objeto com o nome e o espaço de nomes da tabela especificados na coleção.

public:
 bool Contains(System::String ^ name, System::String ^ tableNamespace);
public bool Contains(string name, string tableNamespace);
member this.Contains : string * string -> bool
Public Function Contains (name As String, tableNamespace As String) As Boolean

Parâmetros

name
String

O nome do DataTable a encontrar.

tableNamespace
String

O nome do DataTable espaço de nomes para consultar.

Devoluções

true se a tabela especificada existir; caso contrário false.

Exemplos

O exemplo seguinte testa se existe uma tabela com o nome "Suppliers" no DataTableCollection.

private void TestForTableName()
{
    // Get the DataSet of a DataGrid.
    DataSet thisDataSet = (DataSet)DataGrid1.DataSource;

    // Get the DataTableCollection through the Tables property.
    DataTableCollection tablesCol = thisDataSet.Tables;

    // Check if the named table exists.
    if (tablesCol.Contains("Suppliers"))
        Console.WriteLine("Table named Suppliers exists");
}
Private Sub TestForTableName()
   ' Get the DataSet of a DataGrid.
   Dim thisDataSet As DataSet = CType(DataGrid1.DataSource, DataSet)

   ' Get the DataTableCollection through the Tables property.
   Dim tablesCol As DataTableCollection = thisDataSet.Tables

   ' Check if the named table exists.
   If tablesCol.Contains("Suppliers") Then 
      Console.WriteLine("Table named Suppliers exists")
   End If
End Sub

Observações

Especifica o nome do DataTable objeto usando a TableName propriedade. Se adicionar a DataTable à coleção com o Add método, sem passar argumentos, a tabela recebe um nome padrão, baseado na ordem em que a tabela foi adicionada ("Table1", "Table2", e assim sucessivamente).

Note

Retorna false quando duas ou mais tabelas têm o mesmo nome mas espaços de nomes diferentes. A chamada não tem sucesso se houver qualquer ambiguidade ao associar um nome de tabela a exatamente uma tabela.

Para obter o índice de um DataTable, use o IndexOf método .

Ver também

Aplica-se a