A more robust solution and complete what I suggest. Knowing that everything has a quick, easy and wrong solution, better spend time on implementation for quality gain!
#region Controle de Transação
using (OracleConnection connection = new OracleConnection(ConfigurationManager.ConnectionStrings["Oracle"].ConnectionString))
using (OracleCommand command = connection.CreateCommand())
{
try
{
connection.Open();
using (var transaction = connection.BeginTransaction())
{
#region excluindo registro da tabela 1'
command.CommandText = Constantes.sql1; //Constantes é uma classe estatica com declarações de variaveis ou constantes estaticas onde centraliza os scripts.
command.CommandType = System.Data.CommandType.Text;
command.Parameters.Add(new OracleParameter("p_codigo ", OracleDbType.int, ParameterDirection.Input)).Value = codigo;
command.ExecuteNonQuery();
command.Parameters.Clear();
#endregion
#region excluindo registro da tabela 2'
command.CommandText = Constantes.sql2;
command.CommandType = System.Data.CommandType.Text;
command.Parameters.Add(new OracleParameter("p_Numreq", OracleDbType.int, ParameterDirection.Input)).Value = codigo;
command.ExecuteNonQuery();
command.Parameters.Clear();
#endregion
#region excluindo registro da tabela n'
command.CommandText = Constantes.sql3;
command.CommandType = System.Data.CommandType.Text;
command.Parameters.Add(new OracleParameter("p_Numreq", OracleDbType.int, ParameterDirection.Input)).Value = codigo;
command.ExecuteNonQuery();
command.Parameters.Clear();
#endregion
transaction.Commit();
}
#endregion
}
//Nestes casos não devolve o requisitorio então não deve atualizar a situação do mesmo!
catch (OracleException oe)
{
var retornoAmigavel = Constantes.Error;
switch (oe.ErrorCode)
{
case 12170:
retornoAmigavel = oe.ErrorCode +"-"+ Constantes.SemConexao;
break;
case 28000:
retornoAmigavel = oe.ErrorCode + "-" + Constantes.ContaBloqueada;
break;
case 1073:
retornoAmigavel = oe.ErrorCode + "-" + Constantes.ErroDeConexao;
break;
case 1:
retornoAmigavel = oe.ErrorCode + "-" + Constantes.ChavePrimariaViolada;
break;
default:
retornoAmigavel = Constantes.ErroGenerico + oe.Message;
break;
}
Console.WriteLine(retornoAmigavel, oe);
}
catch (Exception e)
{
var EretornoAmigavel = "ERROR REQ.Nº: " + requ.numero;
EretornoAmigavel += "\nConstantes.ErroGenerico " + e.Message;
Console.WriteLine(EretornoAmigavel);
}
}
#endregion
That's it! I hope I contributed ...