次の方法で共有


DataColumnCollection.Item プロパティ (String)

指定した名前の DataColumn をコレクションから取得します。

[C#] C# では、このプロパティは DataColumnCollection クラスのインデクサになります。

Overloads Public Overridable Default ReadOnly Property Item( _
   ByVal name As String _) As DataColumn
[C#]
public virtual DataColumn this[stringname] {get;}
[C++]
public: __property virtual DataColumn* get_Item(String* name);
[JScript]
returnValue = DataColumnCollectionObject.Item(name);またはreturnValue = DataColumnCollectionObject(name);

[JScript] JScript では、この型で定義されている既定のインデックス プロパティを使用することができます。しかし、独自のインデックス プロパティを明示的に定義することはできません。ただし、このクラスの expando 属性を指定すると、既定のインデックス プロパティが提供されます。提供されるインデックス プロパティの型は Object 型であり、インデックス型は String になります。

引数 [JScript]

パラメータ [Visual Basic, C#, C++]

プロパティ値

コレクション内の指定した ColumnNameDataColumnDataColumn が存在しない場合は null 値。

解説

Item は、列名の検索時に条件付きで大文字と小文字を区別します。たとえば、"mydatacolumn" という名前と "Mydatacolumn" という名前の DataColumn がある場合、この 2 つの列のいずれかの検索に使用される文字列は大文字と小文字を区別して処理されます。ただし、"mydatacolumn" という名前は存在するが "Mydatacolumn" という名前が存在しない場合、検索文字列は大文字と小文字を区別しないで処理されます。

使用例

[Visual Basic, C#, C++] Item プロパティを使用して、インデックスで指定した DataColumn オブジェクトの DataType 値を出力する例を次に示します。

 
Private Sub PrintDataType(dt As DataTable)
    Dim cols As DataColumnCollection
    ' Get the DataColumnCollection from a DataTable in a DataSet.
    cols = dt.Columns
    ' Print the column's data type.
    Console.WriteLine(cols("id").DataType)
End Sub

[C#] 
private void PrintDataType(DataTable dt){
    DataColumnCollection cols ;
   // Get the DataColumnCollection from a DataTable in a DataSet.
   cols = dt.Columns;
   // Print the column's data type.
   Console.WriteLine(cols["id"].DataType);
}

[C++] 
private:
 void PrintDataType(DataTable* dt){
     DataColumnCollection* cols ;
    // Get the DataColumnCollection from a DataTable in a DataSet.
    cols = dt->Columns;
    // Print the column's data type.
    Console::WriteLine(cols->Item[S"id"]->DataType);
 }

[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 ファミリ

参照

DataColumnCollection クラス | DataColumnCollection メンバ | System.Data 名前空間 | DataColumnCollection.Item オーバーロードの一覧 | ColumnName | Contains | DataColumn