/// <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, SqlHelper9.Con)) { cmd.CommandType = commandType; cmd.Parameters.AddRange(param); SqlHelper9.Con.Open(); OracleDataReader reader = cmd.ExecuteReader(CommandBehavior.CloseConnection); while (reader.Read()) { obj = SqlHelper9.ExecuteDataReader <T>(reader); } } } finally { if (SqlHelper9.Con.State != ConnectionState.Closed) { SqlHelper9.Con.Close(); } } return(obj); }
/// <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, SqlHelper9.Con)) { try { cmd.CommandType = commandType; if (param != null) { cmd.Parameters.AddRange(param); } SqlHelper9.Con.Open(); OracleDataReader reader = cmd.ExecuteReader(CommandBehavior.CloseConnection); while (reader.Read()) { T obj = SqlHelper9.ExecuteDataReader <T>(reader); list.Add(obj); } } catch (Exception ex) { list = null; } } } finally { if (SqlHelper9.Con.State != ConnectionState.Closed) { SqlHelper9.Con.Close(); } } return(list); }