Condividi tramite


DataTableCollection.Contains Metodo

Definizione

Ottiene un valore che indica se un DataTable oggetto con il nome specificato esiste nell'insieme.

Overload

Nome Descrizione
Contains(String)

Ottiene un valore che indica se un DataTable oggetto con il nome specificato esiste nell'insieme.

Contains(String, String)

Ottiene un valore che indica se un DataTable oggetto con il nome e lo spazio dei nomi della tabella specificati sono presenti nell'insieme.

Contains(String)

Origine:
DataTableCollection.cs
Origine:
DataTableCollection.cs
Origine:
DataTableCollection.cs
Origine:
DataTableCollection.cs
Origine:
DataTableCollection.cs

Ottiene un valore che indica se un DataTable oggetto con il nome specificato esiste nell'insieme.

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

Parametri

name
String

Nome dell'oggetto DataTable da trovare.

Restituisce

true se la tabella specificata esiste; in caso contrario false, .

Esempio

Nell'esempio seguente viene verificato se una tabella con il nome "Suppliers" esiste in 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

Commenti

Specificare il nome dell'oggetto DataTable utilizzando la TableName proprietà . Se si aggiunge un oggetto DataTable alla raccolta con il Add metodo , non viene passato alcun argomento, alla tabella viene assegnato un nome predefinito, in base all'ordine in cui è stata aggiunta la tabella ("Table1", "Table2" e così via).

Per ottenere l'indice di un DataTableoggetto , usare il IndexOf metodo .

Annotazioni

Restituisce false quando due o più tabelle hanno lo stesso nome ma spazi dei nomi diversi. La chiamata non riesce se si verifica un'ambiguità quando si associa un nome di tabella esattamente a una tabella.

Vedi anche

Si applica a

Contains(String, String)

Origine:
DataTableCollection.cs
Origine:
DataTableCollection.cs
Origine:
DataTableCollection.cs
Origine:
DataTableCollection.cs
Origine:
DataTableCollection.cs

Ottiene un valore che indica se un DataTable oggetto con il nome e lo spazio dei nomi della tabella specificati sono presenti nell'insieme.

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

Parametri

name
String

Nome dell'oggetto DataTable da trovare.

tableNamespace
String

Nome dello DataTable spazio dei nomi da cercare.

Restituisce

true se la tabella specificata esiste; in caso contrario false, .

Esempio

Nell'esempio seguente viene verificato se una tabella con il nome "Suppliers" esiste in 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

Commenti

Specificare il nome dell'oggetto DataTable utilizzando la TableName proprietà . Se si aggiunge un oggetto DataTable alla raccolta con il Add metodo , non viene passato alcun argomento, alla tabella viene assegnato un nome predefinito, in base all'ordine in cui è stata aggiunta la tabella ("Table1", "Table2" e così via).

Annotazioni

Restituisce false quando due o più tabelle hanno lo stesso nome ma spazi dei nomi diversi. La chiamata non riesce se si verifica un'ambiguità quando si associa un nome di tabella esattamente a una tabella.

Per ottenere l'indice di un DataTableoggetto , usare il IndexOf metodo .

Vedi anche

Si applica a