Compartir por


DataTableCollection.Contains Método

Definición

Obtiene un valor que indica si existe un DataTable objeto con el nombre especificado en la colección.

Sobrecargas

Nombre Description
Contains(String)

Obtiene un valor que indica si existe un DataTable objeto con el nombre especificado en la colección.

Contains(String, String)

Obtiene un valor que indica si existe un DataTable objeto con el nombre y el espacio de nombres de tabla especificados en la colección.

Contains(String)

Source:
DataTableCollection.cs
Source:
DataTableCollection.cs
Source:
DataTableCollection.cs
Source:
DataTableCollection.cs
Source:
DataTableCollection.cs

Obtiene un valor que indica si existe un DataTable objeto con el nombre especificado en la colección.

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

Nombre del objeto que DataTable se va a buscar.

Devoluciones

true si existe la tabla especificada; de lo contrario false, es .

Ejemplos

En el ejemplo siguiente se comprueba si existe una tabla con el nombre "Proveedores" en .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

Comentarios

Especifique el nombre del DataTable objeto mediante la TableName propiedad . Si agrega un DataTable elemento a la colección con el Add método , no se pasa ningún argumento, la tabla recibe un nombre predeterminado, en función del orden en el que se agregó la tabla ("Table1", "Table2", etc.).

Para obtener el índice de un DataTable, use el IndexOf método .

Nota:

Devuelve false cuando dos o más tablas tienen el mismo nombre pero espacios de nombres diferentes. La llamada no se realiza correctamente si hay alguna ambigüedad al hacer coincidir un nombre de tabla con exactamente una tabla.

Consulte también

Se aplica a

Contains(String, String)

Source:
DataTableCollection.cs
Source:
DataTableCollection.cs
Source:
DataTableCollection.cs
Source:
DataTableCollection.cs
Source:
DataTableCollection.cs

Obtiene un valor que indica si existe un DataTable objeto con el nombre y el espacio de nombres de tabla especificados en la colección.

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

Nombre del objeto que DataTable se va a buscar.

tableNamespace
String

Nombre del espacio de nombres en el DataTable que se va a buscar.

Devoluciones

true si existe la tabla especificada; de lo contrario false, es .

Ejemplos

En el ejemplo siguiente se comprueba si existe una tabla con el nombre "Proveedores" en .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

Comentarios

Especifique el nombre del DataTable objeto mediante la TableName propiedad . Si agrega un DataTable elemento a la colección con el Add método , no se pasa ningún argumento, la tabla recibe un nombre predeterminado, en función del orden en el que se agregó la tabla ("Table1", "Table2", etc.).

Nota:

Devuelve false cuando dos o más tablas tienen el mismo nombre pero espacios de nombres diferentes. La llamada no se realiza correctamente si hay alguna ambigüedad al hacer coincidir un nombre de tabla con exactamente una tabla.

Para obtener el índice de un DataTable, use el IndexOf método .

Consulte también

Se aplica a