Executes a SQL SELECT statement and returns a single value.
NotOverridable Public Function ExecuteScalar() As Object _
public object ExecuteScalar();
The first column of the first row in the result set, or a null reference (Nothing in Visual Basic) if the result set is empty.
The statement is the current ULCommand object, with the ULCommand.CommandText and any ULCommand.Parameters as required.
If this method is called on a query that returns multiple rows and columns, only the first column of the first row is returned.
If the ULCommand.CommandType is System.Data.CommandType.TableDirect, ExecuteScalar performs an ULCommand.ExecuteTable() and returns the first column of the first row.
It is recommended that SELECT statements used with this method to create read-only result sets end with FOR READ ONLY. For some statements that use temporary tables, there may be a significant performance improvement.
ULException class - A SQL error occurred.
InvalidOperationException - The command is in an invalid state. Either the ULCommand.Connection is missing or closed, the ULCommand.Transaction value does not match the current transaction state of the connection, or the ULCommand.CommandText is invalid.