コード例 #1
0
ファイル: OrclDbHelper4.cs プロジェクト: linklovesj/gzhz-etl
        /// <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, SqlHelper4.Con))
                {
                    cmd.CommandType = commandType;
                    cmd.Parameters.AddRange(param);
                    SqlHelper4.Con.Open();
                    OracleDataReader reader = cmd.ExecuteReader(CommandBehavior.CloseConnection);
                    while (reader.Read())
                    {
                        obj = SqlHelper4.ExecuteDataReader <T>(reader);
                    }
                }
            }
            finally
            {
                if (SqlHelper4.Con.State != ConnectionState.Closed)
                {
                    SqlHelper4.Con.Close();
                }
            }
            return(obj);
        }
コード例 #2
0
ファイル: OrclDbHelper4.cs プロジェクト: linklovesj/gzhz-etl
        /// <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, SqlHelper4.Con))
                {
                    try
                    {
                        cmd.CommandType = commandType;

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

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

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