Class IDatabaseHandlerExtensions
Extension methods for IDatabaseHandler adding some often used functionality
Inheritance
Inherited Members
Namespace: EPiServer.Data
Assembly: EPiServer.Framework.AspNet.dll
Version: 11.20.7Syntax
public static class IDatabaseHandlerExtensions
Methods
CreateParameter(IDatabaseHandler, String, DbType, ParameterDirection, Object)
Creates a System.Data.Common.DbParameter with the given arguments.
Declaration
public static DbParameter CreateParameter(this IDatabaseHandler handler, string name, DbType type, ParameterDirection direction, object value)
Parameters
Type | Name | Description |
---|---|---|
IDatabaseHandler | 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(IDatabaseHandler, String, Object)
Creates a System.Data.Common.DbParameter with the specified name and value
Declaration
public static DbParameter CreateParameter(this IDatabaseHandler handler, string name, object value)
Parameters
Type | Name | Description |
---|---|---|
IDatabaseHandler | 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(IDatabaseHandler)
Creates a System.Data.Common.DbParameter for a return value of type System.Data.DbType.Int32
Declaration
public static DbParameter CreateReturnParameter(this IDatabaseHandler handler)
Parameters
Type | Name | Description |
---|---|---|
IDatabaseHandler | 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(IDatabaseHandler, 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 IDatabaseHandler handler, string commandText, CommandType commandType, params object[] parameterValues)
Parameters
Type | Name | Description |
---|---|---|
IDatabaseHandler | 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(IDatabaseHandler, 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 IDatabaseHandler handler, string storedProcedureName, params object[] parameterValues)
Parameters
Type | Name | Description |
---|---|---|
IDatabaseHandler | 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(IDatabaseHandler, DbCommand, String)
Retrieve a value from a parameter in a System.Data.Common.DbCommand
Declaration
public static object GetParameterValue(this IDatabaseHandler handler, DbCommand cmd, string name)
Parameters
Type | Name | Description |
---|---|---|
IDatabaseHandler | 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(IDatabaseHandler, String, CommandType, Object[])
Gets an open System.Data.Common.DbDataReader from the current connection with the given arguments.
Declaration
public static DbDataReader GetReader(this IDatabaseHandler handler, string commandText, CommandType commandType, params object[] parameterValues)
Parameters
Type | Name | Description |
---|---|---|
IDatabaseHandler | 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(IDatabaseHandler, String, Object[])
Gets an open System.Data.Common.DbDataReader from the current connection with the given arguments.
Declaration
public static DbDataReader GetReader(this IDatabaseHandler handler, string storedProcedureName, params object[] parameterValues)
Parameters
Type | Name | Description |
---|---|---|
IDatabaseHandler | 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(IDatabaseHandler, DbCommand)
Retrieve the return value created with CreateReturnParameter
Declaration
public static int GetReturnValue(this IDatabaseHandler handler, DbCommand cmd)
Parameters
Type | Name | Description |
---|---|---|
IDatabaseHandler | 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(IDatabaseHandler, 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 IDatabaseHandler handler, string commandText, CommandType commandType, params object[] parameterValues)
Parameters
Type | Name | Description |
---|---|---|
IDatabaseHandler | 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(IDatabaseHandler, 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 IDatabaseHandler handler, string storedProcedureName, params object[] parameterValues)
Parameters
Type | Name | Description |
---|---|---|
IDatabaseHandler | 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(IDatabaseHandler, DbCommand, String, Object)
Set a value to a parameter in a System.Data.Common.DbCommand.
Declaration
public static void SetParameterValue(this IDatabaseHandler handler, DbCommand cmd, string name, object parameterValue)
Parameters
Type | Name | Description |
---|---|---|
IDatabaseHandler | 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 |