Object is returned when calling ExecuteScalar method of command object - ADO.NET

Q.  What datatype is returned when calling the ExecuteScalar method of a command object?
- Published on 28 Jul 15

a. System.Int32
b. Object
c. No. of effected records
d. None of the above

ANSWER: Object
 

    Discussion

  • Ramesh   -Posted on 19 Oct 15
    The return type of ExecuteScalar method of a command object is object. It returns the first column of the first row in the result set.
    Example:
    SqlCommand cmd=new SqlCommand();
    cmd.CommandText = "SELECT COUNT(*) FROM employee";
    Int32 count = (Int32) cmd.ExecuteScalar();

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.)