I've come to realize that I'm having trouble writing information to the bank because:
-I am running a block of a method that writes data to the database:
//codigo aqui
MySQLCallDB.InsertData("PEDIDOS", columns, values); //gravando informações
//codigo quebra por alguma Exception aqui ou seja, terei um Pedido sem Detalhes
MySQLCallDB.InsertData("PEDIDOS_DETALHES", columns, values); //gravando informações
//Restante do código
The InsertData
method is of a static class that manages the queries in my application ( MySQLCallDB
) and the code and the way I call MYSQL in InsertData
is:
public static string InsertData(string table, List < string > columns, List < string > values) {
string Query = "QUERY";
Query += "SELECT LAST_INSERT_ID() as ID;";
MySqlCommand comm = new MySqlCommand("", conexao);
comm.CommandText = Query;
try {
conexao.Open();
MySqlDataReader reader = comm.ExecuteReader();
reader.Read();
return reader.GetString("ID");
}
catch (Exception e) {
Debug.WriteLine(Query);
Debug.WriteLine(e);
return "Error";
}
finally {
conexao.Close(); //Fechando a conexão}}
}
}
The question is: in cases where an Exception that breaks the whole process (as described in the code comments), what should I do to not have information without logic inside the bank?