Reputation: 2515
i am trying to return results from IEnumerable and i am interested in one column which contains what i am looking for. But with what i have based on a member's suggested answer selecting a certain column value from looping in ienumerable i am getting a compile error:
public IEnumerable<Guid> GetGuids(int id)
{
using (SqlCommand _command = new SqlCommand("StoredProc"))
{
_command.Connection = new SqlConnection(conString);
_command.Connection.Open();
_command.CommandType = CommandType.StoredProcedure;
_command.Parameters.AddWithValue("@ItemID", id);
return _command.ExecuteReader()
.Cast<DbDataRecord>()
.Select(r => (Guid)r.Item["GuidColumn"]);
}
}
Error: that DbDataRecord does not contain a definition for Item
.
How do i go about that?
Upvotes: 0
Views: 103
Reputation: 15158
I believe it should be:
return _command.ExecuteReader()
.Cast<DbDataRecord>()
.Select(r =>(Guid) r["GuidColumn"]);
Upvotes: 3