Rollback in flat file database in Sage 100 with BOI

I am creating a Sales Order Invoice ( SO_Invoice_bus ) with .Net C# which mean I am inserting the Header and the Details info. My problem is if there is a exception in the code inserting the lines, nothing is inserted in Details but the Header info is inserted.

Is there any way to avoid this happens, I mean make something like a rollback. 

PS: Any language suggestion is accepted.