I have 3 tables in Oracle database. From my asp.net C# page, I am inserting records into all three tables as shown below:
INSERT INTO contactMaster
(contactID, FName, MName, LName)
VALUES
(contactID.NextVal, 'John', 'G', 'Garnet')
INSERT INTO contactPhone
(contactPhoneID, contactID, contactType, phonenum)
VALUES
(contactPhoneID.NextVal, 1, 2, 1234567890)
INSERT INTO contactAddress
(contactAddressID, contactID, addressType, PHN, Street, City)
VALUES
(contactAddressID.NextVal, 1, 1, 287, 'Blooper St', 'New Yor')
My question is, how do I make sure that either all the above are executed or none is executed in C#.
If the first 2nd or 3rd insert fails, everything should fail.
Use a SQL transaction to ensure atomicity:
C#: OracleTransaction
Alternative
The insert statements could be moved to a stored procedure (preferably within a package), so only a single query be made from C#.