DataTableCollection.Item[] 属性   
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
从集合中获取指定的 DataTable 对象。
重载
| Item[Int32] | 获取位于指定索引位置的 DataTable 对象。 | 
| Item[String] | 获取具有指定名称的 DataTable 对象。 | 
| Item[String, String] | 获取指定命名空间中具有指定名称的 DataTable 对象。 | 
Item[Int32]
- Source:
- DataTableCollection.cs
- Source:
- DataTableCollection.cs
- Source:
- DataTableCollection.cs
获取位于指定索引位置的 DataTable 对象。
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.DataTableDefault Public ReadOnly Property Item(index As Integer) As DataTable参数
属性值
具有DataTable指定索引的 ;如果 不存在,DataTable则null为 。
例外
索引值大于集合中的项目数。
示例
以下示例按索引检索 DataTable 。
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使用 方法确定是否存在具有特定索引的表。
如果具有表的名称,但没有表的索引,请使用 IndexOf 方法返回索引。
另请参阅
适用于
Item[String]
- Source:
- DataTableCollection.cs
- Source:
- DataTableCollection.cs
- Source:
- DataTableCollection.cs
获取具有指定名称的 DataTable 对象。
public:
 property System::Data::DataTable ^ default[System::String ^] { System::Data::DataTable ^ get(System::String ^ name); };public System.Data.DataTable? this[string? name] { get; }public System.Data.DataTable this[string name] { get; }member this.Item(string) : System.Data.DataTableDefault Public ReadOnly Property Item(name As String) As DataTable参数
- name
- String
要查找的 DataTable 的名称。
属性值
具有指定名称的 DataTable;否则,如果 DataTable 不存在,则为 null。
示例
以下示例从 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
注解
DataTable如果存在与搜索字符串大小写匹配的名称,则返回该名称。 否则将执行不区分大小写的搜索,如果 DataTable 找到与此搜索匹配的名称,则返回该搜索。
Contains使用 方法确定是否存在具有特定名称或索引的表。
适用于
Item[String, String]
- Source:
- DataTableCollection.cs
- Source:
- DataTableCollection.cs
- Source:
- DataTableCollection.cs
获取指定命名空间中具有指定名称的 DataTable 对象。
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; }public System.Data.DataTable this[string name, string tableNamespace] { get; }member this.Item(string * string) : System.Data.DataTableDefault Public ReadOnly Property Item(name As String, tableNamespace As String) As DataTable参数
- name
- String
要查找的 DataTable 的名称。
属性值
具有指定名称的 DataTable;否则,如果 DataTable 不存在,则为 null。