0

I am having confusion in ExecuteScalar & ExecuteReader

If we use ExecuteReader for select with aggregate function, it will not give any error and run successfully so if we can do both queries select with aggregate & select with non aggregate with the help of only one method ExecuteReader so why is there ExecuteScalar………, is there any other benefit of it?

Please give the proper answer

3
Contributors
3
Replies
4
Views
10 Years
Discussion Span
Last Post by chan_lemo
0

The main difference is the "footprint" of the return value. ExecuteReader always returns an object, for example, a SqlDataReader. Then, to get the actual results, you have to do a Read(), then get the value.

ExecuteScalar immediately returns the actual value.

So, in terms of retrieving Scalar data from a database, ExecuteScalar is more efficient.

0

Thanx......

The main difference is the "footprint" of the return value. ExecuteReader always returns an object, for example, a SqlDataReader. Then, to get the actual results, you have to do a Read(), then get the value.

ExecuteScalar immediately returns the actual value.

So, in terms of retrieving Scalar data from a database, ExecuteScalar is more efficient.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.