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 9008901
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T02:03:29+00:00 2026-06-16T02:03:29+00:00

I have 2 tables enquiry and details. On save button click I have written

  • 0

I have 2 tables enquiry and details.
On save button click I have written

fbsave();
fbsavedetails();

fbsave() save the data in enquiry table and fbsavedetails() saves data in details table.

now if error occur in fbsavedetails() then both steps should be rollback.

is it possible?

  • 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-06-16T02:03:30+00:00Added an answer on June 16, 2026 at 2:03 am

    You can explicitly create a transaction and pass that around, i.e.

    using(var connection = ...)
    {
        connection.Open();
        using (var tran = connection.BeginTransaction())
        {
            try
            {
                FBSave(connection, tran);
                FBSaveDetails(connection, tran);
                tran.Commit();
            }
            catch
            {
                tran.Rollback();
                throw;
            }
        }
    }
    

    Note that here you must also set the Transaction on each command, hence why you need to pass it in, and all the commands must be on the same connection object.


    Or: you can use TransactionScope; it is important that the Open() happens inside the TransactionScope to get automatic enlistment:

    using(var tran = new TransactionScope())
    {
        FBSave();
        FBSaveDetails();
        tran.Complete();
    }
    

    or:

    using(var tran = new TransactionScope())
    using(var connection = ...)
    {
        connection.Open();
        FBSave(connection);
        FBSaveDetails(connection);
        tran.Complete();
    }
    

    with the TransactionScope approach, you don’t need to set anything special – most of it is automatic. You can of course optionally pass the connection into the methods, but they could also obtain their own connection, and in most cases it would work fine.

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

Sidebar

Related Questions

I have tables of data samples, with a timestamp and some data. Each table
I have tables A , B and C . Now table A as column
I have tables with buttons/links/email with mailto: and have written a default double click
I have tables linked by FK, I query on the first table using entity
have tables like this Table checklist idCardno name permAddress datetime Table persons name idcardno
I have tables item and store (it's a store management system). item table has
I have tables foo and bar: create table foo(a int, b varchar(10), primary key
I have tables named Events and Log. The Events table comprises of ID, Event
I have tables like this fake ones: data: id type month value 1 1
I have an enquiry about MySQL statement about combining two rows in a table

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.