DataTableCollection.Contains Método

Definição

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

Sobrecargas

Contains(String)

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

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.

Contains(String)

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

public:
 bool Contains(System::String ^ name);
public bool Contains (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 ser localizado.

Retornos

Boolean

true se a tabela especificada existir. Caso contrário, false.

Exemplos

O exemplo a DataTableCollectionseguir testa se existe uma tabela com o nome "Fornecedores" no .

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

Comentários

Especifique o nome do DataTable objeto usando a TableName propriedade. Se você adicionar um DataTable à coleção com o Add método, não passando argumentos, a tabela recebe um nome padrão, com base na ordem em que a tabela foi adicionada ("Table1", "Table2" e assim por diante).

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

Observação

Retorna false quando duas ou mais tabelas têm o mesmo nome, mas namespaces diferentes. A chamada não terá êxito se houver qualquer ambiguidade durante a correspondência de um nome de tabela para exatamente uma tabela.

Confira também

Aplica-se a

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.

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 ser localizado.

tableNamespace
String

O nome do namespace DataTable a ser pesquisado.

Retornos

Boolean

true se a tabela especificada existir. Caso contrário, false.

Exemplos

O exemplo a DataTableCollectionseguir testa se existe uma tabela com o nome "Fornecedores" no .

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

Comentários

Especifique o nome do DataTable objeto usando a TableName propriedade. Se você adicionar um DataTable à coleção com o Add método, não passando argumentos, a tabela recebe um nome padrão, com base na ordem em que a tabela foi adicionada ("Table1", "Table2" e assim por diante).

Observação

Retorna false quando duas ou mais tabelas têm o mesmo nome, mas namespaces diferentes. A chamada não terá êxito se houver qualquer ambiguidade durante a correspondência de um nome de tabela para exatamente uma tabela.

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

Confira também

Aplica-se a