Пример #1
0
        /// <summary>
        /// Constructs the parameter using the DESQLParamater instance
        /// </summary>
        /// <param name="paramName">Name of the parameter.</param>
        /// <param name="paramValue">The parameter value.</param>
        /// <param name="paramType">Type of the parameter. Default SqlDbType.NVarchar</param>
        /// <param name="paramDirection">The parameter direction. Default ParameterDirection.Input</param>
        /// <returns>DESQLParameter instance with details</returns>
        protected DESQLParameter ConstructParameter(string paramName, object paramValue, SqlDbType paramType = SqlDbType.NVarChar, ParameterDirection paramDirection = ParameterDirection.Input)
        {
            DESQLParameter parameterPiece = new DESQLParameter();

            parameterPiece.ParamDirection = paramDirection;
            parameterPiece.ParamName      = paramName;
            parameterPiece.ParamType      = paramType;
            parameterPiece.ParamValue     = paramValue;
            return(parameterPiece);
        }
Пример #2
0
        /// <summary>
        /// Attaches the parameters to the given SQL command instance
        /// </summary>
        /// <param name="givenSqlCommand">The given SQL command.</param>
        /// <returns></returns>
        private ErrorObj AttachParametersToCommand(SqlCommand givenSqlCommand)
        {
            ErrorObj err = new ErrorObj();

            if (!(_commandElement.CommandParameter == null))
            {
                if (_commandElement.CommandParameter.Count > 0)
                {
                    System.Collections.Generic.List <DESQLParameter> paramaterList = _commandElement.CommandParameter;
                    DESQLParameter parameterPiece = default(DESQLParameter);
                    foreach (DESQLParameter tempLoopVar_parameterPiece in paramaterList)
                    {
                        parameterPiece = tempLoopVar_parameterPiece;
                        SqlParameter tempSqlParameter = new SqlParameter();
                        if ((!(err.HasError)) && HasValue(parameterPiece.ParamName))
                        {
                            tempSqlParameter.ParameterName = parameterPiece.ParamName;
                        }
                        else
                        {
                            err.HasError     = true;
                            err.ErrorMessage = ERROR_COMMANDPARAMETERNAME;
                            break;
                        }
                        //If paramValue is nothing considering it as DBNull.Value
                        if (parameterPiece.ParamValue == null)
                        {
                            tempSqlParameter.Value = DBNull.Value;
                        }
                        else
                        {
                            if ((!(err.HasError)) && HasValue(parameterPiece.ParamValue, parameterPiece.ParamType))
                            {
                                tempSqlParameter.SqlDbType = parameterPiece.ParamType;
                                tempSqlParameter.Value     = parameterPiece.ParamValue;
                            }
                            else
                            {
                                err.HasError     = true;
                                err.ErrorMessage = ERROR_COMMANDPARAMETERTYPEVALUE;
                                break;
                            }
                        }
                        if (!(err.HasError))
                        {
                            if (parameterPiece.ParamDirection == null)
                            {
                                parameterPiece.ParamDirection = ParameterDirection.Input;
                            }
                            tempSqlParameter.Direction = parameterPiece.ParamDirection;
                        }
                        if (!(err.HasError))
                        {
                            givenSqlCommand.Parameters.Add(tempSqlParameter);
                        }
                        tempSqlParameter = null;
                    }
                    parameterPiece = null;
                    //tempSqlParameter = Nothing
                }
            }
            return(err);
        }