コード例 #1
0
ファイル: SqlHelper.cs プロジェクト: lima66/AppStage
        /// <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();
            }
        }
コード例 #2
0
ファイル: SqlHelper.cs プロジェクト: lima66/AppStage
        /// <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()));
            }
        }
コード例 #3
0
ファイル: SqlHelper.cs プロジェクト: lima66/AppStage
        /// <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));
            }
        }
コード例 #4
0
ファイル: SqlHelper.cs プロジェクト: lima66/AppStage
 /// <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));
 }
コード例 #5
0
ファイル: SqlHelper.cs プロジェクト: lima66/AppStage
 /// <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));
 }