Class IDatabaseExecutorExtensions
Extension methods for IDatabaseExecutor adding some often used functionality
Inheritance
Inherited Members
Namespace: EPiServer.Data
Assembly: EPiServer.Data.dll
Version: 11.20.7Syntax
public static class IDatabaseExecutorExtensions
Methods
CreateParameter(IDatabaseExecutor, String, DbType, ParameterDirection, Object)
Creates a System.Data.Common.DbParameter with the given arguments.
Declaration
public static DbParameter CreateParameter(this IDatabaseExecutor handler, string name, DbType type, ParameterDirection direction, object value)
Parameters
Type | Name | Description |
---|---|---|
IDatabaseExecutor | handler | The handler to execute the method on. |
System.String | name | The name of the parameter to create |
System.Data.DbType | type | The database type of the parameter to create |
System.Data.ParameterDirection | direction | The direction of the parameter to create |
System.Object | value | A created parameter |
Returns
Type | Description |
---|---|
System.Data.Common.DbParameter |
CreateParameter(IDatabaseExecutor, String, Object)
Creates a System.Data.Common.DbParameter with the specified name and value
Declaration
public static DbParameter CreateParameter(this IDatabaseExecutor handler, string name, object value)
Parameters
Type | Name | Description |
---|---|---|
IDatabaseExecutor | handler | The handler to execute the method on. |
System.String | name | Name of the parameter |
System.Object | value | The value to be added to the parameter (will determine the type) |
Returns
Type | Description |
---|---|
System.Data.Common.DbParameter | A parameter populated with name and value |
CreateReturnParameter(IDatabaseExecutor)
Creates a System.Data.Common.DbParameter for a return value of type System.Data.DbType.Int32
Declaration
public static DbParameter CreateReturnParameter(this IDatabaseExecutor handler)
Parameters
Type | Name | Description |
---|---|---|
IDatabaseExecutor | handler | The handler to execute the method on. |
Returns
Type | Description |
---|---|
System.Data.Common.DbParameter | An instance of System.Data.Common.DbParameter configured as a return parameter |
Remarks
You can use GetReturnValue to retrieve the value of parameters created with this method
ExecuteNonQuery(IDatabaseExecutor, String, CommandType, Object[])
Executes a non query using the supplied stored procedure or SQL query and parameter values from the currently opened connection.
Declaration
public static object ExecuteNonQuery(this IDatabaseExecutor handler, string commandText, CommandType commandType, params object[] parameterValues)
Parameters
Type | Name | Description |
---|---|---|
IDatabaseExecutor | handler | The handler to execute the method on. |
System.String | commandText | The stored procedure name or the SQL query to run. |
System.Data.CommandType | commandType | How to interprete the data supplied in the |
System.Object[] | parameterValues | Any parameter values to add to the stored procedure or SQL query. |
Returns
Type | Description |
---|---|
System.Object |
ExecuteNonQuery(IDatabaseExecutor, String, Object[])
Executes a non query using the supplied stored procedure or SQL query and parameter values from the currently opened connection.
Declaration
public static object ExecuteNonQuery(this IDatabaseExecutor handler, string storedProcedureName, params object[] parameterValues)
Parameters
Type | Name | Description |
---|---|---|
IDatabaseExecutor | handler | The handler to execute the method on. |
System.String | storedProcedureName | The stored procedure name. |
System.Object[] | parameterValues | Any parameter values to add to the stored procedure. |
Returns
Type | Description |
---|---|
System.Object |
GetParameterValue(IDatabaseExecutor, DbCommand, String)
Retrieve a value from a parameter in a System.Data.Common.DbCommand
Declaration
public static object GetParameterValue(this IDatabaseExecutor handler, DbCommand cmd, string name)
Parameters
Type | Name | Description |
---|---|---|
IDatabaseExecutor | handler | The handler to execute the method on. |
System.Data.Common.DbCommand | cmd | The command object from which the value should be retrieved |
System.String | name | The name of the parameter from which the value should be retrieved |
Returns
Type | Description |
---|---|
System.Object | The value of the parameter |
Exceptions
Type | Condition |
---|---|
System.Data.DataException | If the parameter does not exist in the collection |
GetReader(IDatabaseExecutor, String, CommandType, Object[])
Gets an open System.Data.Common.DbDataReader from the current connection with the given arguments.
Declaration
public static DbDataReader GetReader(this IDatabaseExecutor handler, string commandText, CommandType commandType, params object[] parameterValues)
Parameters
Type | Name | Description |
---|---|---|
IDatabaseExecutor | handler | The handler to execute the method on. |
System.String | commandText | The stored procedure name or the SQL query to run. |
System.Data.CommandType | commandType | How to interprete the data supplied in the |
System.Object[] | parameterValues | Any parameter values to add to the stored procedure or SQL query. |
Returns
Type | Description |
---|---|
System.Data.Common.DbDataReader | A database reader the current connection by executing the given stored procedure or SQL query with the supplied parameter values. |
GetReader(IDatabaseExecutor, String, Object[])
Gets an open System.Data.Common.DbDataReader from the current connection with the given arguments.
Declaration
public static DbDataReader GetReader(this IDatabaseExecutor handler, string storedProcedureName, params object[] parameterValues)
Parameters
Type | Name | Description |
---|---|---|
IDatabaseExecutor | handler | The handler to execute the method on. |
System.String | storedProcedureName | The stored procedure name. |
System.Object[] | parameterValues | Any parameter values to add to the stored procedure. |
Returns
Type | Description |
---|---|
System.Data.Common.DbDataReader | A database reader the current connection by executing the given stored procedure with the supplied parameter values. |
GetReturnValue(IDatabaseExecutor, DbCommand)
Retrieve the return value created with CreateReturnParameter
Declaration
public static int GetReturnValue(this IDatabaseExecutor handler, DbCommand cmd)
Parameters
Type | Name | Description |
---|---|---|
IDatabaseExecutor | handler | The handler to execute the method on. |
System.Data.Common.DbCommand | cmd | The command object from which the return value should be extracted |
Returns
Type | Description |
---|---|
System.Int32 | The value of the parameter named "ReturnValue" |
GetScalar(IDatabaseExecutor, String, CommandType, Object[])
Gets a scalar value using the given commant text and parameter values from the currently opened connection.
Declaration
public static object GetScalar(this IDatabaseExecutor handler, string commandText, CommandType commandType, params object[] parameterValues)
Parameters
Type | Name | Description |
---|---|---|
IDatabaseExecutor | handler | The handler to execute the method on. |
System.String | commandText | The stored procedure name or the SQL query to run. |
System.Data.CommandType | commandType | How to interprete the data supplied in the |
System.Object[] | parameterValues | Any parameter values to add to the stored procedure or SQL query. |
Returns
Type | Description |
---|---|
System.Object | A scalar value using the current connection by executing the given stored procedure or SQL query with the supplied parameter values. |
GetScalar(IDatabaseExecutor, String, Object[])
Gets a scalar value using the given commant text and parameter values from the currently opened connection.
Declaration
public static object GetScalar(this IDatabaseExecutor handler, string storedProcedureName, params object[] parameterValues)
Parameters
Type | Name | Description |
---|---|---|
IDatabaseExecutor | handler | The handler to execute the method on. |
System.String | storedProcedureName | The stored procedure name. |
System.Object[] | parameterValues | Any parameter values to add to the stored procedure. |
Returns
Type | Description |
---|---|
System.Object | A scalar value using the current connection by executing the given stored procedure with the supplied parameter values. |
SetParameterValue(IDatabaseExecutor, DbCommand, String, Object)
Set a value to a parameter in a System.Data.Common.DbCommand.
Declaration
public static void SetParameterValue(this IDatabaseExecutor handler, DbCommand cmd, string name, object parameterValue)
Parameters
Type | Name | Description |
---|---|---|
IDatabaseExecutor | handler | The handler to execute the method on. |
System.Data.Common.DbCommand | cmd | The command object on which the value should be set. |
System.String | name | The name of the parameter on which the value should be set. |
System.Object | parameterValue | The value of the parameter to be set. |
Exceptions
Type | Condition |
---|---|
System.Data.DataException | If the parameter does not exist in the collection |