What is the difference between ExecuteNonQuery, ExecuteScalar and ExecuteReader?
All these methods are used to manipulate or retrieve data from the database. The details are as folllows:
ExecuteNonQuery
The method executes a transaction (Insert/Update/Delete) and returns the number of rows affected, in addition if there are triggers associated with the table the number of rows affected by that will also be returned.
ExecuteSclar
The methods only returns the value from the first cell of the first row, this is used for commands like COUNT etc which returns a single value.
ExecuteReader
This method is used to read data from the table and return the same, the return value creates a SQLDataReader object.
Comments
Post a Comment