DataTableCollection.Item[] 屬性

定義

從集合中取得指定的 DataTable 物件。

多載

名稱 Description
Item[Int32]

取得 DataTable 指定索引的物件。

Item[String]

取得 DataTable 指定名稱的物件。

Item[String, String]

取得 DataTable 指定命名空間中擁有指定名稱的物件。

Item[Int32]

取得 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.DataTable
Default Public ReadOnly Property Item(index As Integer) As DataTable

參數

index
Int32

尋找的零基指數 DataTable

屬性值

DataTable A 具有指定索引;否則null若不存在。DataTable

例外狀況

索引值大於集合中項目數量。

範例

以下範例是透過索引檢索 a 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]

取得 DataTable 指定名稱的物件。

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 名稱。

屬性值

DataTable A,名稱指定;否則null若不存在。DataTable

範例

以下範例從 中以名稱 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]

取得 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; }
member this.Item(string * string) : System.Data.DataTable
Default Public ReadOnly Property Item(name As String, tableNamespace As String) As DataTable

參數

name
String

要找到的 DataTable 名稱。

tableNamespace
String

要查的命名空間名稱 DataTable

屬性值

DataTable A,名稱指定;否則null若不存在。DataTable

適用於