/// <summary> /// Gets the enum value. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="reader">The reader.</param> /// <param name="name">The name.</param> /// <returns></returns> /*internal static T GetEnumValue<T>(this DbDataReader reader, string name) * { * try * { * int index = reader.GetOrdinal(name); * * if (reader.IsDBNull(index)) * return default(T); * * return Conversion.GetEnumValue<T>(reader.GetValue(index)); * } * catch (InvalidCastException) * { * throw new InvalidCastException(string.Format("Column '{0}' type is not compatible with type '{1}'", name, typeof(T))); * } * }*/ /// <summary> /// Executes the non query. /// </summary> /// <param name="connection">The connection.</param> /// <param name="commandText">The command text.</param> /// <param name="commandType">Type of the command.</param> /// <param name="parameters">The parameters.</param> internal static void ExecuteNonQuery( this SqlConnection connection, string commandText, CommandType commandType, params SqlParameter[] parameters) { using (SqlCommand command = SqlHelper.CreateCommand(connection, commandText, commandType)) { if (parameters.Length > 0) { command.Parameters.AddRange(parameters); } command.ExecuteNonQuery(); } }
/// <summary> /// Executes the scalar. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="connection">The connection.</param> /// <param name="commandText">The command text.</param> /// <param name="commandType">Type of the command.</param> /// <param name="parameters">The parameters.</param> /// <returns></returns> internal static T ExecuteScalar <T>( this SqlConnection connection, string commandText, CommandType commandType, params SqlParameter[] parameters) { using (SqlCommand command = SqlHelper.CreateCommand(connection, commandText, commandType)) { if (parameters.Length > 0) { command.Parameters.AddRange(parameters); } return(ConvertValue <T>(command.ExecuteScalar())); } }
/// <summary> /// Executes the reader. /// </summary> /// <param name="connection">The connection.</param> /// <param name="commandText">The command text.</param> /// <param name="commandType">Type of the command.</param> /// <param name="commandBehavior">The command behavior.</param> /// <param name="parameters">The parameters.</param> /// <returns></returns> internal static SqlDataReader ExecuteReader( this SqlConnection connection, string commandText, CommandType commandType, CommandBehavior commandBehavior, params SqlParameter[] parameters) { using (SqlCommand command = SqlHelper.CreateCommand(connection, commandText, commandType)) { if (parameters.Length > 0) { command.Parameters.AddRange(parameters); } return(command.ExecuteReader(commandBehavior)); } }
/// <summary> /// Creates the command. /// </summary> /// <param name="connection">The connection.</param> /// <param name="commandText">The command text.</param> /// <param name="commandType">Type of the command.</param> /// <returns></returns> internal static SqlCommand CreateCommand(SqlConnection connection, string commandText, CommandType commandType) { return(SqlHelper.CreateCommand(connection, commandText, commandType, null)); }
/// <summary> /// Creates the command. /// </summary> /// <param name="connection">The connection.</param> /// <returns></returns> internal static SqlCommand CreateCommand(SqlConnection connection) { return(SqlHelper.CreateCommand(connection, string.Empty, CommandType.Text, null)); }