DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/)
-   ASP.NET (http://www.daniweb.com/forums/forum18.html)
-   -   ExecuteRedear vs ExecuteScalar (http://www.daniweb.com/forums/thread44984.html)

rajni11 May 8th, 2006 2:12 am
ExecuteRedear vs ExecuteScalar
 
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

tgreer May 10th, 2006 4:45 pm
Re: ExecuteRedear vs ExecuteScalar
 
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.

rajni11 May 11th, 2006 1:08 am
Re: ExecuteRedear vs ExecuteScalar
 
Thanx......




Quote:

Originally Posted by tgreer
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.



All times are GMT -4. The time now is 11:47 pm.

Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC