Question - Explain the ExecuteScalar method in ADO.NET?
Answer -
The ExecuteScalar Method in SqlCommandObject returns the first column of the first row after executing the query against the Data Source.
- If the result set contain more than one column or rows, it takes only the first column of the first row. All other values are ignored.
- If the result set is empty it will return null.
Int32 TotalSalary = Convert.ToInt32(cmd.ExecuteScalar());