System.Data.Generic
DataSourceExecuteScalarT Method (String, TransactionContext, T) |
Executes the query, and returns the first column of the first row in the result set returned by the query. Supports transactions.
Namespace: System.Data.Generic
Assembly: System.Data.Generic (in System.Data.Generic.dll) Version: 1.9.5473.30542 (1.9.5473.2392)

public T ExecuteScalar<T>( string SQL, TransactionContext transaction, T defaultValue )
Public Function ExecuteScalar(Of T) ( SQL As String, transaction As TransactionContext, defaultValue As T ) As T
public: generic<typename T> T ExecuteScalar( String^ SQL, TransactionContext^ transaction, T defaultValue )
member ExecuteScalar : SQL : string * transaction : TransactionContext * defaultValue : 'T -> 'T
Parameters
- SQL
- Type: SystemString
Transact-SQL statement to execute against the connection. - transaction
- Type: System.Data.GenericTransactionContext
Context of the transaction. - defaultValue
- Type: T
Default value to return in case of no return.
Type Parameters
- T
- Type to return.
Return Value
Type: TThe first column of the first row in the result set, or a null reference (Nothing in Visual Basic) if the result set is empty. Returns a maximum of 2033 characters.

Exception | Condition |
---|---|
ArgumentNullException | In case the SQL is null. |
SqlException | In case the underlying connection cause an exception. |

