SqlHelper..::..ExecuteScalar Method (SqlTransaction, CommandType, String, array<SqlParameter>[]()[][])

Execute a SqlCommand (that returns a 1x1 resultset) against the specified SqlTransaction using the provided parameters.

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

Syntax


public static Object ExecuteScalar(
	SqlTransaction transaction,
	CommandType commandType,
	string commandText,
	params SqlParameter[] commandParameters
)

Parameters

transaction
Type: SqlTransaction
A valid SqlTransaction
commandType
Type: CommandType
The CommandType (stored procedure, text, etc.)
commandText
Type: String
The stored procedure name or T-SQL command
commandParameters
Type: array<SqlParameter>[]()[][]
An array of SqlParamters used to execute the command

Return Value

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

Exceptions


ExceptionCondition
ArgumentNullExceptiontransaction
ArgumentExceptionThe transaction was rollbacked or commited, please provide an open transaction. - transaction

Remarks


e.g.: int orderCount = (int)ExecuteScalar(trans, CommandType.StoredProcedure, "GetOrderCount", new SqlParameter("@prodid", 24));