Show / Hide Table of Contents

ExecuteScalar

This method executes the query and returns the first column of the first row of results Other rows and columns are ignored.

using (var cmd = new DatabaseCommand(mySqlConnection))
{
    cmd.CommandText = "SELECT COUNT(*) FROM EMP";
    var nbEmployees = cmd.ExecuteScalar<int>();
}

If no data are found, the result will be null (for a nullable type) or the default value of this type (0 in the previous example).

All execution commands are available in synchronous and asynchronous (Async) mode.

  • Improve this Doc
In This Article
Back to top Developed By Denis Voituron