DataTableCollection.Item[String, String] 属性

定义

从集合中获取指定的 DataTable 对象。Gets the specified DataTable object from the collection.

重载

Item[Int32]

获取位于指定索引位置的 DataTable 对象。Gets the DataTable object at the specified index.

Item[String]

获取具有指定名称的 DataTable 对象。Gets the DataTable object with the specified name.

Item[String, String]

获取指定命名空间中具有指定名称的 DataTable 对象。Gets the DataTable object with the specified name in the specified namespace.

Item[Int32]

获取位于指定索引位置的 DataTable 对象。Gets the DataTable object at the specified index.

public:
 property System::Data::DataTable ^ default[int] { System::Data::DataTable ^ get(int index); };
public System.Data.DataTable this[int index] { get; }
member this.Item(int) : System.Data.DataTable
Default Public ReadOnly Property Item(index As Integer) As DataTable

参数

index
Int32

要查找的 DataTable 的从零开始的索引。The zero-based index of the DataTable to find.

属性值

具有DataTable指定索引的; 否则null ,如果DataTable不存在,则为。A DataTable with the specified index; otherwise null if the DataTable does not exist.

异常

索引值大于集合中的项目数。The index value is greater than the number of items in the collection.

示例

下面的示例DataTable按索引检索。The following example retrieves a DataTable by its index.

private void GetDataTableByIndex()
{
   // presuming a DataGrid is displaying more than one table, get its DataSet.
   DataSet thisDataSet = (DataSet)DataGrid1.DataSource;
   // Get the DataTableCollection.
   DataTableCollection tablesCollection = thisDataSet.Tables;
   // Iterate through the collection to get each table name.
   for (int i = 0; i < tablesCollection.Count; i++)
      Console.WriteLine(tablesCollection[i].TableName);
}
Private Sub GetDataTableByIndex()
    ' Presuming a DataGrid is displaying more than one table, get its DataSet.
    Dim thisDataSet As DataSet = CType(DataGrid1.DataSource, DataSet)

    ' Get the DataTableCollection.
    Dim tablesCollection As DataTableCollection = thisDataSet.Tables

    ' Iterate through the collection to get each table name.
    Dim i As Integer
    For i = 0 To tablesCollection.Count - 1
       Console.WriteLine(tablesCollection(i).TableName)
    Next
End Sub

注解

Contains使用方法可确定具有特定索引的表是否存在。Use the Contains method to determine whether a table with a specific index exists.

如果您具有表的名称,而不是索引的名称,请使用IndexOf方法返回索引。If you have the name of a table, but not its index, use the IndexOf method to return the index.

另请参阅

Item[String]

获取具有指定名称的 DataTable 对象。Gets the DataTable object with the specified name.

public:
 property System::Data::DataTable ^ default[System::String ^] { System::Data::DataTable ^ get(System::String ^ name); };
public System.Data.DataTable this[string name] { get; }
member this.Item(string) : System.Data.DataTable
Default Public ReadOnly Property Item(name As String) As DataTable

参数

name
String

要查找的 DataTable 的名称。The name of the DataTable to find.

属性值

具有指定名称的 DataTable;否则,如果 DataTable 不存在,则为 nullA DataTable with the specified name; otherwise null if the DataTable does not exist.

示例

下面的示例按名称从中DataTableCollection检索一个表。The following example retrieves a single table by name from the DataTableCollection.

private void GetTableByName()
{
    // Presuming a DataGrid is displaying more than one table, get its DataSet.
    DataSet thisDataSet = (DataSet)DataGrid1.DataSource;

    // Get the DataTableCollection.
    DataTableCollection tablesCollection = thisDataSet.Tables;

    // Get a specific table by name.
    DataTable table = tablesCollection["Suppliers"];
    Console.WriteLine(table.TableName);
}
Private Sub GetTableByName()
    ' Presuming a DataGrid is displaying more than one table, 
    ' get its DataSet.
    Dim thisDataSet As DataSet = CType(DataGrid1.DataSource, DataSet)

    ' Get the DataTableCollection.
    Dim tablesCollection As DataTableCollection = thisDataSet.Tables

    ' Get a specific table by name.
    Dim table As DataTable = tablesCollection("Suppliers")
    Console.WriteLine(table.TableName)
End Sub

注解

如果存在与搜索字符串的大小写匹配的名称,则返回该名称。DataTableIf a DataTable name exists that matches the case of the search string, it is returned. 否则,将执行不区分大小写的搜索,如果DataTable找到与此搜索匹配的名称,则返回该名称。Otherwise a case-insensitive search is performed, and if a DataTable name is found that matches this search, it is returned.

Contains使用方法可确定具有特定名称或索引的表是否存在。Use the Contains method to determine whether a table with a specific name or index exists.

Item[String, String]

获取指定命名空间中具有指定名称的 DataTable 对象。Gets the DataTable object with the specified name in the specified namespace.

public:
 property System::Data::DataTable ^ default[System::String ^, System::String ^] { System::Data::DataTable ^ get(System::String ^ name, System::String ^ tableNamespace); };
public System.Data.DataTable this[string name, string tableNamespace] { get; }
member this.Item(string * string) : System.Data.DataTable
Default Public ReadOnly Property Item(name As String, tableNamespace As String) As DataTable

参数

name
String

要查找的 DataTable 的名称。The name of the DataTable to find.

tableNamespace
String

作为查找范围的 DataTable 命名空间的名称。The name of the DataTable namespace to look in.

属性值

具有指定名称的 DataTable;否则,如果 DataTable 不存在,则为 nullA DataTable with the specified name; otherwise null if the DataTable does not exist.

适用于