示例#1
0
        /// <summary>
        /// 执行返回一条记录的泛型对象
        /// </summary>
        /// <typeparam name="T">泛型类型</typeparam>
        /// <param name="commandText">Oracle语句或存储过程名</param>
        /// <param name="commandType">Oracle命令类型</param>
        /// <param name="param">Oracle命令参数数组</param>
        /// <returns>实体对象</returns>
        public static T ExecuteEntity <T>(string commandText, CommandType commandType, params OracleParameter[] param)
        {
            T obj = default(T);

            try
            {
                using (OracleCommand cmd = new OracleCommand(commandText, SqlHelper3.Con))
                {
                    cmd.CommandType = commandType;
                    cmd.Parameters.AddRange(param);
                    SqlHelper3.Con.Open();
                    OracleDataReader reader = cmd.ExecuteReader(CommandBehavior.CloseConnection);
                    while (reader.Read())
                    {
                        obj = SqlHelper3.ExecuteDataReader <T>(reader);
                    }
                }
            }
            finally
            {
                if (SqlHelper3.Con.State != ConnectionState.Closed)
                {
                    SqlHelper3.Con.Close();
                }
            }
            return(obj);
        }
示例#2
0
        /// <summary>
        /// 执行返回多条记录的泛型集合对象
        /// </summary>
        /// <typeparam name="T">泛型类型</typeparam>
        /// <param name="commandText">Oracle语句或存储过程名</param>
        /// <param name="commandType">Oracle命令类型</param>
        /// <param name="param">Oracle命令参数数组</param>
        /// <returns>泛型集合对象</returns>
        public static List <T> ExecuteList <T>(string commandText, CommandType commandType, params OracleParameter[] param)
        {
            List <T> list = new List <T>();

            try
            {
                using (OracleCommand cmd = new OracleCommand(commandText, SqlHelper3.Con))
                {
                    try
                    {
                        cmd.CommandType = commandType;

                        if (param != null)
                        {
                            cmd.Parameters.AddRange(param);
                        }
                        SqlHelper3.Con.Open();

                        OracleDataReader reader = cmd.ExecuteReader(CommandBehavior.CloseConnection);

                        while (reader.Read())
                        {
                            T obj = SqlHelper3.ExecuteDataReader <T>(reader);
                            list.Add(obj);
                        }
                    }
                    catch (Exception ex)
                    {
                        list = null;
                    }
                }
            }
            finally
            {
                if (SqlHelper3.Con.State != ConnectionState.Closed)
                {
                    SqlHelper3.Con.Close();
                }
            }
            return(list);
        }