Execute a stored procedure via an IDbCommand (that returns a 1x1 resultset) against the specified
IDbTransaction using the provided parameter values. This method will query the database to discover the parameters for the
stored procedure (the first time each stored procedure is called), and assign the values based on parameter order.
Namespace: CodeSmith.EngineAssembly: CodeSmith.Engine (in CodeSmith.Engine.dll) Version: 6.0.0.0 (7.0.0.15127)
Syntax
C# |
---|
public virtual Object ExecuteScalar( IDbTransaction transaction, string spName, params Object[] parameterValues ) |
Visual Basic |
---|
Public Overridable Function ExecuteScalar ( transaction As IDbTransaction, spName As String, ParamArray parameterValues As Object() ) As Object |
Parameters
- transaction
- Type: System.Data..::..IDbTransaction
A valid IDbTransaction
- spName
- Type: System..::..String
The name of the stored procedure
- parameterValues
- Type: array<System..::..Object>[]()[][]
An array of objects to be assigned as the input values of the stored procedure
Return Value
Type: ObjectAn object containing the value in the 1x1 resultset generated by the command
Remarks
This method provides no access to output parameters or the stored procedure's return value parameter.
Examples
Copy | |
---|---|
int orderCount = (int)helper.ExecuteScalar(tran, "GetOrderCount", 24, 36); |
Exceptions
Exception | Condition |
---|---|
System..::..InvalidOperationException | Thrown if any of the IDataParameters.ParameterNames are null, or if the parameter count does not match the number of values supplied |
System..::..ArgumentNullException | Thrown if commandText is null |
System..::..ArgumentNullException | Thrown if spName is null |
System..::..ArgumentException | Thrown if the parameter count does not match the number of values supplied |
System..::..ArgumentNullException | Thrown if transaction is null |
System..::..ArgumentNullException | Thrown if transaction.Connection is null |
System..::..ArgumentException | Thrown if the transaction is rolled back or commmitted |