指定した DataTable オブジェクトをコレクションから取得します。
[C#] C# では、このプロパティは DataTableCollection クラスのインデクサになります。
オーバーロードの一覧
指定した名前の DataTable オブジェクトを取得します。
[Visual Basic] Overloads Public Default ReadOnly Property Item(String) As DataTable
[JScript] DataTableCollection.Item (String)
指定したインデックス位置にある DataTable を取得します。
[Visual Basic] Overloads Public Default ReadOnly Property Item(Integer) As DataTable
[JScript] DataTableCollection.Item (int)
使用例
[Visual Basic, C#, C++] インデックスで DataTable を取得する例を次に示します。
[Visual Basic, C#, C++] メモ ここでは、Item プロパティ (DataTableCollection インデクサ) のオーバーロード形式のうちの 1 つだけについて、使用例を示します。その他の例については、各オーバーロード形式のトピックを参照してください。
Private Sub GetDataTableByIndex()
' Presuming a DataGrid is displaying more than one table, get its DataSet.
Dim dSet As DataSet = CType(DataGrid1.DataSource, DataSet)
' Get the DataTableCollection.
Dim tablesCol As DataTableCollection = dSet.Tables
' Iterate through the collection to get each table name.
Dim i As Integer
For i = 0 To tablesCol.Count - 1
Console.WriteLine(tablesCol(i).TableName)
Next
End Sub
[C#]
private void GetDataTableByIndex()
{
// presuming a DataGrid is displaying more than one table, get its DataSet.
DataSet dSet = (DataSet)DataGrid1.DataSource;
// Get the DataTableCollection.
DataTableCollection tablesCol = dSet.Tables;
// Iterate through the collection to get each table name.
for (int i = 0; i < tablesCol.Count; i++)
Console.WriteLine(tablesCol[i].TableName);
}
[C++]
private:
void GetDataTableByIndex()
{
// presuming a DataGrid is displaying more than one table, get its DataSet.
DataSet* dSet = dynamic_cast<DataSet*>(DataGrid1->DataSource);
// Get the DataTableCollection.
DataTableCollection* tablesCol = dSet->Tables;
// Iterate through the collection to get each table name.
for (int i = 0; i < tablesCol->Count; i++)
Console::WriteLine(tablesCol->Item[i]->TableName);
}
[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン をクリックします。
参照
DataTableCollection クラス | DataTableCollection メンバ | System.Data 名前空間