语言

DataTableCollection.Contains 方法

定义

获取一个值,该值指示集合中是否存在 DataTable 具有指定名称的对象。

重载

名称 说明
Contains(String)

获取一个值,该值指示集合中是否存在 DataTable 具有指定名称的对象。

Contains(String, String)

获取一个值,该值指示集合中是否存在 DataTable 具有指定名称和表命名空间的对象。

Contains(String)

Source:
DataTableCollection.cs
Source:
DataTableCollection.cs
Source:
DataTableCollection.cs
Source:
DataTableCollection.cs
Source:
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

注解

使用DataTable属性指定对象的名称TableName。 如果使用该方法向集合DataTable添加一个Add参数,则根据添加表的顺序(“Table1”、“Table2”等)为表指定默认名称。

若要获取 a DataTable的索引,请使用 IndexOf 该方法。

注释

当 false 两个或多个表具有相同的名称但命名空间不同时返回。 如果在将表名称与一个表完全匹配时存在任何歧义,则调用不会成功。

另请参阅

适用于

Contains(String, String)

Source:
DataTableCollection.cs
Source:
DataTableCollection.cs
Source:
DataTableCollection.cs
Source:
DataTableCollection.cs
Source:
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

注解

使用DataTable属性指定对象的名称TableName。 如果使用该方法向集合DataTable添加一个Add参数,则根据添加表的顺序(“Table1”、“Table2”等)为表指定默认名称。

注释

当 false 两个或多个表具有相同的名称但命名空间不同时返回。 如果在将表名称与一个表完全匹配时存在任何歧义,则调用不会成功。

若要获取 a DataTable的索引,请使用 IndexOf 该方法。

另请参阅

适用于