dotConnect for Salesforce Documentation
Devart.Common Namespace / DbCommandBase Class / ExecuteScalar Method
Example

In This Topic
    ExecuteScalar Method
    In This Topic
    Executes the query, and returns the first column of the first row in the result set returned by the query. Extra columns or rows are ignored.
    Syntax
    'Declaration
     
    Public Overrides Function ExecuteScalar() As Object
    public override object ExecuteScalar()

    Return Value

    The first column of the first row in the result set.
    Remarks
    Use the ExecuteScalar method to retrieve a single value (for example, an aggregate value) from a data source. This requires less code than using the System.Data.Common.DbCommand.ExecuteReader method, and then performing the operations necessary to generate the single value from the data returned by a DbDataReaderBase.
    Example
    This example shows typical usage of ExecuteScalar method
    using(SalesforceConnection conn = new SalesforceConnection(connectionString)) {
      conn.Open();
      SalesforceCommand cmd = conn.CreateCommand();
      cmd.CommandText = "SELECT count(*) as NumberOfRegions FROM regions";
      Int64 count = Convert.ToInt64(cmd.ExecuteScalar()); 
    }
    Dim conn As New SalesforceConnection(connectionString)
    conn.Open()
    Dim cmd As SalesforceCommand = conn.CreateCommand()
    cmd.CommandText = "SELECT count(*) as NumberOfRegions FROM regions"
    Dim count As Int64 = Convert.ToInt64(cmd.ExecuteScalar()); 
    conn.Close()
    Requirements

    Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

    See Also