Item
objectvalue
= DataReader[int columnOrdinal]; objectvalue
= DataReader[stringcolumnName
];
The Item
property is also the default indexer for
the DataReader
. It allows you to retrieve a value
from any field by specifying the column name or column ordinal. This
value is returned as an object and is stored in the native
provider-specific format. You can cast this object to the desired
type.
Here is an example of how to retrieve a value from the
OrderPrice
field and convert it to the .NET
decimal type:
decimal price = (decimal)r["OrderPrice"];
You can also retrieve the same information using a column ordinal.
This is a zero-based number that corresponds to the order in which
fields were retrieved. Assuming the OrderPrice
field is the second field in the result set, use the following
equivalent syntax:
decimal price = (decimal)r[1];