SqlHelper..::..ExecuteScalar Method (SqlConnection, CommandType, String)

Execute a SqlCommand (that returns a 1x1 resultset and takes no parameters) against the provided SqlConnection.

Namespace:  Core
Assembly:  Core (in Core.dll)

Syntax


public static Object ExecuteScalar(
	SqlConnection connection,
	CommandType commandType,
	string commandText
)

Parameters

connection
Type: SqlConnection
A valid SqlConnection
commandType
Type: CommandType
The CommandType (stored procedure, text, etc.)
commandText
Type: String
The stored procedure name or T-SQL command

Return Value

An object containing the value in the 1x1 resultset generated by the command

Remarks


e.g.: int orderCount = (int)ExecuteScalar(conn, CommandType.StoredProcedure, "GetOrderCount");