What is the difference between ExecuteScalar, ExecuteReader and ExecuteNonQuery?
ExecuteReader:
Used for any result which returns multiple rows / columns. Mostly used for select statements.
ExecuteScalar:
Used for any result which return only single value. if it returns more that 1 row/column, then the result is the first column of the first row.
Mostly used in aggregate functions like sum, avg etc.
ExecuteNonQuery:
Used in queries which does not return any data. Mostly used with Delete, Update, Insert queries.
Used for any result which returns multiple rows / columns. Mostly used for select statements.
ExecuteScalar:
Used for any result which return only single value. if it returns more that 1 row/column, then the result is the first column of the first row.
Mostly used in aggregate functions like sum, avg etc.
ExecuteNonQuery:
Used in queries which does not return any data. Mostly used with Delete, Update, Insert queries.
Comments
Post a Comment