예제 #1
0
        /// <summary>
        /// Creates the sequence of parameters.
        /// </summary>
        /// <param name="parameters"> Paramters given with KeyValuePair.</param>
        /// <param name="operationInfo"> Operation info. </param>
        /// <returns> Returns the sequence of parameters. </returns>
        private static SqlParameter[] BuildParameters(KeyValuePair <string, object>[] parameters, OperationInfo operationInfo)
        {
            //constructing the array of paramaters
            var sqlParameters = new SqlParameter[parameters.Length];

            for (var counter = 0; counter < sqlParameters.Length; counter++)
            {
                //constrcuting parameters
                var parameterInfo = operationInfo.ParametersList[counter].Split(new[] { ' ' },
                                                                                StringSplitOptions.RemoveEmptyEntries);
                sqlParameters[counter] = new SqlParameter();
                sqlParameters[counter].ParameterName = parameterInfo[0];
                sqlParameters[counter].Value         = parameters[counter].Value;
                sqlParameters[counter].SqlDbType     = (SqlDbType)Enum.Parse(typeof(SqlDbType), parameterInfo[2]);
            }

            //return the parameters
            return(sqlParameters);
        }
예제 #2
0
        /// <summary>
        /// Builds the command.
        /// </summary>
        /// <param name="connection"> Connection.</param>
        /// <param name="sqlParameters"> Parameters. </param>
        /// <param name="operationInfo"> Operation info. </param>
        /// <returns> Returns the command. </returns>
        private static SqlCommand BuildCommand(SqlConnection connection, SqlParameter[] sqlParameters, OperationInfo operationInfo)
        {
            //constructing command
            var sqlCommand = new SqlCommand();

            sqlCommand.CommandText = operationInfo.OperationCode;
            sqlCommand.Connection  = connection;
            sqlCommand.CommandType = (CommandType)Enum.Parse(typeof(CommandType),
                                                             operationInfo.OperationType);

            //if there is no parameters(for example "GetBooks") ,then parameters must not be added to sql command.
            if (sqlParameters != null)
            {
                sqlCommand.Parameters.AddRange(sqlParameters);
            }

            //return command
            return(sqlCommand);
        }