VistaDB 5
Example 






ExecuteScalar Method
Executes the query and returns the first column of the first row in the result set returned by the query. All other columns and rows are ignored.
Syntax
'Declaration
 
Public Overrides NotOverridable Function ExecuteScalar() As System.Object
'Usage
 
Dim instance As VistaDBCommand
Dim value As System.Object
 
value = instance.ExecuteScalar()
public override System.object ExecuteScalar()
public function ExecuteScalar(): System.TObject; override; 
public override function ExecuteScalar() : System.Object;
public: System.Object* ExecuteScalar(); override 
public:
System.Object^ ExecuteScalar(); override 

Return Value

The first column of the first row in the result set as an object.
Example
The following example return row count for table Orders.
public int GetOrdersRowCount(VistaDBConnection connection)
{
	VistaDBCommand command = new VistaDBCommand("SELECT COUNT(*) FROM Orders", connection);
	object result = command.ExecuteScalar();
	// Test if the result came back as null
	if( result != null )
		return( (int) result);
	
	return( -1 );
}
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