ExecuteScalar returns value of first column of first row - ADO.NET
Q. Which SqlCommand execution returns the value of the first column of the first row from a table?- Published on 31 Aug 15
EecuteScalar method of SqlCommand object returns the value of the first column of the first row from a table.
The common methods of command abject are as follows.
• ExecuteReader: This method works on select SQL query. It returns the DataReader object. Use DataReader read () method to retrieve the rows.
• ExecuteScalar: This method returns single value. Its return type is Object.If you call ExecuteScalar method with a SQL statement that returns rows of data, the query returns only the first column of the first row.
• ExecuteNonQuery: If you are using Insert, Update or Delete SQL statement then use this method. Its return type is Integer (The number of affected records).