Gets the column from the collection with the specified name.
[C#] In C#, this member is the indexer for the ColumnsCollection class.
[Visual Basic] Overloads Overridable Public Default ReadOnly Property Item( _ ByVal name As String _ ) As DataColumn [C#] public DataColumn this[ string name ] {virtual get;} [C++] public: __property virtual DataColumn* get_Item( String* name ); [JScript] returnValue = ColumnsCollectionObject.Item(name); -or- returnValue = ColumnsCollectionObject(name);
[JScript] In JScript, you can use the default indexed properties defined by a type, but you cannot explicitly define your own. However, specifying the expando attribute on a class automatically provides a default indexed Item property whose type is Object and whose index type is String.
The DataColumn in the collection with the specified ColumnName.
Exception Type | Condition |
---|---|
IndexOutOfRange(System.String) | The collection doesn't have a column with this name. |
Item is case-sensitive when searching for column names. Therefore, if two columns exist, such as "Fname" and "fname," Item property (ColumnsCollection indexer)will find the specific column you name.
The following example uses the Item property (ColumnsCollection indexer) to print the DataType value of a DataColumn object specified by index.
[Visual Basic]
Dim cols As DataColumns ' Get the ColumnsCollection from a DataTable in a DataSet. cols = DataSet1.Tables("Orders").Columns ' Print the DataType of the column named "id." Console.WriteLine(cols("id").DataType.ToString)
ColumnsCollection Class | ColumnsCollection Members | System.Data Namespace | ColumnsCollection.Item Overload List | ColumnName | Contains | DataColumn