Beispiel #1
0
        public static SqlDbType GetDBType(DBParam dbParam)
        {
            var sqlDbType = SqlDbType.NVarChar;

            switch (dbParam.DbType)
            {
            case CommonDbType.Integer:
                sqlDbType = SqlDbType.Int;
                break;

            case CommonDbType.DateTime:
                sqlDbType = SqlDbType.DateTime;
                break;

            case CommonDbType.Boolean:
                sqlDbType = SqlDbType.Bit;
                break;

            case CommonDbType.StringAscii:
                sqlDbType = SqlDbType.VarChar;
                break;

            case CommonDbType.StringUnicode:
                sqlDbType = SqlDbType.NVarChar;
                break;

            case CommonDbType.Guid:
                sqlDbType = SqlDbType.UniqueIdentifier;
                break;

            case CommonDbType.TextAscii:
                sqlDbType = SqlDbType.Text;
                break;

            case CommonDbType.TextUnicode:
                sqlDbType = SqlDbType.NText;
                break;

            case CommonDbType.Money:
                sqlDbType = SqlDbType.Money;
                break;
            }
            return(sqlDbType);
        }
Beispiel #2
0
        public override int PutWithProc(string procName, List <DBParam> parameters, bool getReturnValue = true)
        {
            int returnValueParamIndex = -1;

            if (getReturnValue)
            {
                DBParam returnValueParam = new DBParam(CommonDbType.Integer, "@RETURN_VALUE", 0);
                returnValueParam.Direction = ParameterDirection.ReturnValue;
                returnValueParamIndex      = parameters.Count;
                parameters.Add(returnValueParam);
            }

            OracleCommand comm = new OracleCommand();

            comm.CommandType = CommandType.StoredProcedure;
            comm.CommandText = procName;
            comm.Connection  = conn;
            if (parameters.Any())
            {
                comm.Parameters.AddRange(parameters.Select(dbParam => new OracleParameter()
                {
                    ParameterName = dbParam.ParameterName,
                    OracleDbType  = OracleDBTypeMapper.GetDBType(dbParam),
                    Direction     = dbParam.Direction,
                    Value         = dbParam.Value,
                }).ToArray());
            }

            int result = comm.ExecuteNonQuery();

            if (getReturnValue)
            {
                result = (int)comm.Parameters[returnValueParamIndex].Value;
            }

            return(result);
        }