Queries that Return a Single Value

You can use the mmBusinessObject.ExecScalar method to execute queries that returns a single value, such as getting a count of records that match a specified criteria.

For example, you could create the following business object method that returns the number of employees.

In C#:

This assumes the business object's DefaultCommandType (usually specified at the ABusinessObject level) is set to CommandType.StoredProcedure

public int GetEmployeeCount()
{
	return (int)this.ExecScalar("GetEmployeeCount");
}

This assumes the business object's DefaultCommandType (usually specified at the ABusinessObject level) is set to CommandType.Text:

public int GetEmployeeCount()
{
    int Count = (int)this.ExecScalar("SELECT COUNT(*) AS Expr1 FROM Employees");
    return Count;
}

And in VB .NET:

This assumes the business object's DefaultCommandType (usually specified at the ABusinessObject level) is set to CommandType.StoredProcedure

Public Function GetEmployeeCount() As Integer
	Return CInt(Me.ExecScalar("GetEmployeeCount"))
End Function

This assumes the business object's DefaultCommandType (usually specified at the ABusinessObject level) is set to CommandType.Text

Public Function GetEmployeeCount() As Integer
	Return CInt(Me.ExecScalar("SELECT COUNT(*) AS Expr1 FROM Employees"))
End Function

See also:
Data Access Overview


© (c) 2026 Oak Leaf Enterprises, Inc., 1996-2026 • Updated: 07/28/18
Comment or report problem with topic