If you need a single value, use ExecuteScalar.
You can get a single value with ExecuteReader ..... but its unnecessary
overhead.
..........
Using IDataReader (which is hte interface) will allow you to future proof
your code, as in the future you could swap out
(for example)
OleDbReader for a SqlReader instead.
Its a basic OO concept.
IDataReader GetEmployees()
{
//this procedure could return either an OleDbReader, a SqlReader, a
OracleReader (sp??) or anything else that implements IDataReader
}
I code to the interface, even though I use a SqlReader 99.9% of the time.
"RP" <rp*********@gmail.comwrote in message
news:0f**********************************@e25g2000 prg.googlegroups.com...
>I saw a code in a class where IDataReader is used to retrieve result
from query, even if only one column is to be retrieved. It uses a
CommandObject with ExecuteReader but not using ExecuteScalar.
For what IDataReader is used and what are the benefits of it as
compared to sime DataReader.