指定した名前の DataTable オブジェクトを取得します。
[C#] C# では、このプロパティは DataTableCollection クラスのインデクサになります。
Overloads Public Default ReadOnly Property Item( _
ByVal name As String _) As DataTable
[C#]
public DataTable this[stringname] {get;}
[C++]
public: __property DataTable* get_Item(String* name);
[JScript]
returnValue = DataTableCollectionObject.Item(name);またはreturnValue = DataTableCollectionObject(name);
[JScript] JScript では、この型で定義されている既定のインデックス プロパティを使用することができます。しかし、独自のインデックス プロパティを明示的に定義することはできません。ただし、このクラスの expando 属性を指定すると、既定のインデックス プロパティが提供されます。提供されるインデックス プロパティの型は Object 型であり、インデックス型は String になります。
引数 [JScript]
- name
検索する DataTable の名前。
パラメータ [Visual Basic, C#, C++]
- name
検索する DataTable の名前。
プロパティ値
指定した名前の DataTable 。指定した名前の DataTable が存在しない場合は null 値。
解説
大文字と小文字を区別して検索が実行され、検索文字列に一致する DataTable 名が存在する場合は、その名前が返されます。それ以外の場合は、大文字と小文字を区別しない検索が実行され、検索文字列に一致する DataTable 名が見つかった場合は、その名前が返されます。
Contains メソッドを使用して、特定の名前またはインデックスを持つテーブルが存在するかどうかを確認します。
使用例
[Visual Basic, C#, C++] DataTableCollection から名前で単一のテーブルを取得する例を次に示します。
Private Sub GetTableByName()
' 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
' Get a specific table by name.
Dim t As DataTable = tablesCol("Suppliers")
Console.WriteLine(t.TableName)
End Sub
[C#]
private void GetTableByName()
{
// Presuming a DataGrid is displaying more than one table, get its DataSet.
DataSet dSet = (DataSet)DataGrid1.DataSource;
// Get the DataTableCollection.
DataTableCollection tablesCol = dSet.Tables;
// Get a specific table by name.
DataTable t = tablesCol["Suppliers"];
Console.WriteLine(t.TableName);
}
[C++]
private:
void GetTableByName()
{
// 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;
// Get a specific table by name.
DataTable* t = tablesCol->Item[S"Suppliers"];
Console::WriteLine(t->TableName);
}
[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン をクリックします。
必要条件
プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ
参照
DataTableCollection クラス | DataTableCollection メンバ | System.Data 名前空間 | DataTableCollection.Item オーバーロードの一覧