What is difference between ExecuteScaler, ExecuteNonQuery and ExecuteDataReader?
ExecuteNonQuery():
will work with Action Queries only (Create,Alter,Drop,Insert,Update,Delete).Returns the count of rows effected by the Query.Return type is intReturn value is optional and can be assigned to an integer variable.
ExecuteReader():
will work with Action and Non-Action Queries (Select)Returns the collection of rows selected by the Query.Return type is DataReader.Return value is compulsory and should be assigned to an another object DataReader.
ExecuteScalar():
will work with Non-Action Queries that contain aggregate functions.Return the first row and first column value of the query result.Return type is object.Return value is compulsory and should be assigned to a variable of required type.
ExecuteScalar() only returns the value from the first column of the first row of your query. ExecuteReader() returns an object that can iterate over the entire result set. ExecuteNonQuery() does not return data at all: only the number of rows affected by an insert, update, or delete.
Execute scaler - return single value Execute NonQuery - return nothing Execute DataReader - return collection