Muhammad Imran Ansari
What is difference between ExecuteScaler, ExecuteNonQuery and ExecuteDataReader

What is difference between ExecuteScaler, ExecuteNonQuery and ExecuteDataReader?

By Muhammad Imran Ansari in .NET on Oct 24 2022
  • Brahma Prakash Shukla
    Oct, 2022 29

    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 int
    Return 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.

    • 3
  • Rajeev Kumar
    Jun, 2023 29

    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.

    • 0
  • Digambar Bhandare
    Jan, 2023 28

    Execute scaler - return single value Execute NonQuery - return nothing Execute DataReader - return collection

    • 0


Most Popular Job Functions


MOST LIKED QUESTIONS