ExecuteScalar is used while working with SqlCommand it returns a single value - ADO.NET

Q.  In a SQL Statement while working with SqlCommand it returns a single value, at that time which method of Command Object will be used?
- Published on 28 Jul 15

a. ExecuteNonQuery
b. ExecuteReader
c. ExecuteScalar
d. All of the above

ANSWER: ExecuteScalar
 

    Discussion

  • Digvijay   -Posted on 19 Oct 15
    If you need to return a single value from a sql query, you can use the ExecuteScalar method. This method always returns the value of the first column from the first row. All other values are ignored. If the result set is empty it will return a null. Its return type is Object.

Post your comment / Share knowledge


Enter the code shown above:

(Note: If you cannot read the numbers in the above image, reload the page to generate a new one.)