DataTableCollection.Item[] 屬性

定義

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

多載

Item[Int32]

取得在指定之索引處的 DataTable 物件。

Item[String]

取得具有指定之名稱的 DataTable 物件。

Item[String, String]

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

Item[Int32]

來源:
DataTableCollection.cs
來源:
DataTableCollection.cs
來源:
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.DataTable
Default Public ReadOnly Property Item(index As Integer) As DataTable

參數

index
Int32

要尋找的 DataTable 之以零為基底的索引。

屬性值

DataTable具有指定索引的 ,否則nullDataTable

例外狀況

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

範例

下列範例會 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]

來源:
DataTableCollection.cs
來源:
DataTableCollection.cs
來源:
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.DataTable
Default 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]

來源:
DataTableCollection.cs
來源:
DataTableCollection.cs
來源:
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.DataTable
Default Public ReadOnly Property Item(name As String, tableNamespace As String) As DataTable

參數

name
String

要尋找之 DataTable 的名稱。

tableNamespace
String

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

屬性值

具有指定之名稱的 DataTable。但如果 DataTable 不存在時,則為 null

適用於