Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3964724
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T03:22:08+00:00 2026-05-20T03:22:08+00:00

I have 3 tables in Oracle database. From my asp.net C# page, I am

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T03:22:09+00:00Added an answer on May 20, 2026 at 3:22 am

    Use a SQL transaction to ensure atomicity:

    public void RunOracleTransaction(string connectionString) {
      using (OracleConnection connection = new OracleConnection(connectionString))
      {
        connection.Open();
    
        OracleCommand command = connection.CreateCommand();
        OracleTransaction transaction;
    
        // Start a local transaction
        transaction = connection.BeginTransaction(IsolationLevel.ReadCommitted);
        // Assign transaction object for a pending local transaction
        command.Transaction = transaction;
    
        try
        {
            command.CommandText = 
                "INSERT INTO contactMaster
                   (contactID, FName, MName, LName) 
                 VALUES
                   (contactID.NextVal, 'John', 'G', 'Garnet')";
            command.ExecuteNonQuery();
    
            command.CommandText = 
                "INSERT INTO contactPhone
                   (contactPhoneID, contactID, contactType, phonenum)     
                 VALUES
                   (contactPhoneID.NextVal, 1, 2, 1234567890)";
            command.ExecuteNonQuery();
    
            command.CommandText = 
                "INSERT INTO contactAddress
                   (contactAddressID, contactID, addressType, PHN, Street, City)
                 VALUES
                   (contactAddressID.NextVal, 1, 1, 287, 'Blooper St', 'New Yor')";
            command.ExecuteNonQuery();
    
            transaction.Commit();
            Console.WriteLine("Both records are written to database.");
        }
        catch (Exception e)
        {
            transaction.Rollback();
            Console.WriteLine(e.ToString());
            Console.WriteLine("Neither record was written to database.");
        }
      }
    }
    

    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#.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have couple of tables in my Oracle database as shown below **IM_FP** FP_ID
I have an " select * from tables..joins... " query on an oracle database,
I need to find all the tables in our Oracle database that have attributes
I have a very large Oracle database, with many many tables and millions of
I have an oracle 10g database that has 2 tables: a REBATES table, and
I have 3 columns in Oracle database having table mytable and i want records
I have two very large enterprise tables in an Oracle 10g database. One table
As security tightening exercise, I'm removing all system privileges from an oracle database user.
I have four DB tables in an Oracle database that need to be rewritten/refreshed
I have to clear certain tables in the oracle database however when I'm having

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.