DataTableCollection.Contains 方法

定義

取得值,指出具有指定名稱的 DataTable 物件是否存在於集合中。

多載

Contains(String)

取得值,指出集合中是否含有具此指定名稱的 DataTable 物件。

Contains(String, String)

取得指出具有所指定名稱和資料表命名空間的 DataTable 物件是否存在於集合中的值。

Contains(String)

來源:
DataTableCollection.cs
來源:
DataTableCollection.cs
來源:
DataTableCollection.cs

取得值,指出集合中是否含有具此指定名稱的 DataTable 物件。

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

參數

name
String

要尋找之 DataTable 的名稱。

傳回

如果指定的資料表存在,則為 true,否則為 false

範例

下列範例會測試 中是否有名稱為 「Suppliers」 的 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

備註

您可以使用 屬性來指定物件TableName的名稱DataTable。 如果您使用 方法將 加入 DataTable 至集合 Add 中,則不會傳遞自變數,則會根據數據表加入的順序,指定數據表的默認名稱 (“Table1”、“Table2”等等) 。

若要取得 的 DataTable索引,請使用 IndexOf 方法。

注意

false當兩個或多個資料表具有相同名稱但不同的命名空間時,傳回 。 如果資料表名稱無法完全與單一資料表相符 (即有任何名稱語意模糊),呼叫就會失敗。

另請參閱

適用於

Contains(String, String)

來源:
DataTableCollection.cs
來源:
DataTableCollection.cs
來源:
DataTableCollection.cs

取得指出具有所指定名稱和資料表命名空間的 DataTable 物件是否存在於集合中的值。

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

參數

name
String

要尋找之 DataTable 的名稱。

tableNamespace
String

要查詢之 DataTable 命名空間的名稱。

傳回

如果指定的資料表存在,則為 true,否則為 false

範例

下列範例會測試 中是否有名稱為 「Suppliers」 的 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

備註

您可以使用 屬性來指定物件TableName的名稱DataTable。 如果您使用 方法將 加入 DataTable 至集合 Add 中,則不會傳遞自變數,則會根據數據表加入的順序,指定數據表的默認名稱 (“Table1”、“Table2”等等) 。

注意

false當兩個或多個資料表具有相同名稱但不同的命名空間時,傳回 。 如果資料表名稱無法完全與單一資料表相符 (即有任何名稱語意模糊),呼叫就會失敗。

若要取得 的 DataTable索引,請使用 IndexOf 方法。

另請參閱

適用於