public void Upd(Editora u) { using (OracleConnection conn = BaseDAO.GetConnection()) { //Define o comando using (OracleCommand cmd = new OracleCommand("EDITORA_tapi.upd", conn)) { cmd.CommandType = CommandType.StoredProcedure; //Define parametros cmd.Parameters.Add("p_ID_EDITORA", u.Id_Editora); cmd.Parameters.Add("p_NOME", u.Nome); //Executa try { conn.Open(); cmd.ExecuteNonQuery(); } catch (SqlException ex) { throw new Exception("Ocorreu o erro(BD): " + ex.Message); } catch (Exception ex) { throw new Exception("Erro: " + ex.Message); } finally { if (conn.State == ConnectionState.Open) { conn.Close(); } } } } }
public List<Editora> Get() { using (OracleConnection conn = BaseDAO.GetConnection()) { //Define o comando using (OracleCommand cmd = new OracleCommand("SELECT ID_EDITORA, NOME FROM EDITORA", conn)) { List<Editora> lista = new List<Editora>(); cmd.CommandType = CommandType.Text; //Executando o select OracleDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { Editora e = new Editora(); e.Id_Editora = Convert.ToInt32(reader["ID_EDITORA"]); e.Nome = Convert.ToString(reader["NOME"]); lista.Add(e); } return lista; } } }