using linq we can easily extract the data reader values without writing more coding.
example for populating anonymous object from datareader
using (SqlDataReader dataReader = command.ExecuteReader())
{
var annonymousObject = from IDataRecord record in dataReader
select new
{
Code = (string)record["Code"],
Description = (string)record["Description"]
};
}
example for populating custom object from datareader
using (SqlDataReader dataReader = command.ExecuteReader())
{
DataRecord dataRecord= (from IDataRecord record in dataReader
select new DataRecord
{
Code = (string) record["Code"],
Description = (string)record["Description"]
}).ToArray();
}