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

  • Home
  • SEARCH
  • 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 8131985
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T09:13:57+00:00 2026-06-06T09:13:57+00:00

I’m relatively new to progrmming and am building my first serious client app. On

  • 0

I’m relatively new to progrmming and am building my first serious client app. On one form I have a button which executes quite a large number of transactions with the SQL database, as follows:

private void btnALSave_Click(object sender, EventArgs e)
    {
        try
        {
            //...consider any Special Actions...//

            bool check = Automation_ALHistory_Saved(cboALHistoryType.Text);
            if (check == true)
            {
                //...create History item...//

                cHistory h = new cHistory();
                h.CaseNo = txtCaseNo.Text;
                h.HistoryType = cboALHistoryType.Text;
                h.HistoryDesc = txtALHistoryNote.Text;
                h.Save();

                //...actioned Diary marked complete...//

                cDiary.Completed(txtDiaryID.Text);                                        

                //...create new Diary (with exceptions)...//

                string strNextDiaryID = "";
                if (cboALHistoryType.Text != "Diary Cancelled" && cboALHistoryType.Text != "Case Closed")
                {
                    aMyDate cM = new aMyDate(txtALNextDueDate.Text);
                    DateTime pDate = cM.GetDate();
                    cDiary d = new cDiary();
                    d.CaseNo = txtCaseNo.Text;
                    d.DiaryType = cboALNextType.Text;
                    d.DiaryUserFor = cboALNextFor.Text;
                    d.DiaryNote = txtALNextNote.Text;
                    d.DiaryDueDate = pDate.ToString();
                    d.Save();
                    strNextDiaryID = d.DiaryID;
                }

                //...invoke KPI Manager...//

                int intActionedDiaryID = Int32.Parse(txtALDiaryID.Text);
                int intHistoryID = Int32.Parse(h.HistoryID);
                int intNextDiaryID = Int32.Parse(strNextDiaryID);
                cKPIManager kpi = new cKPIManager(intActionedDiaryID, intHistoryID, intNextDiaryID);

                //...reset forms...//

                ClearActionLinks();
                PopulateForm();
                tabCase.SelectTab("tabDiary");
            }
        }
        catch (Exception eX)
        {
            string eM = "Error attempting to save Diary / History Actions";
            aError err = new aError(eX, eM);
            MessageBox.Show(eM + Environment.NewLine + eX.Message);
        }
    }      

What all of this does isn’t important for the purposes of my question. What I really need to know, is what is the best way, to prevent (or undo) all the changes made to the database during the running of this method, IF it should fail at ANY point. Basically I need the success (or otherwise) of the method to be an ‘all or nothing’ scenario. Should the method fail at the last line, I need to undo everything the method had done before that (in terms of the changes it has made to the data on the server).

Advise for this beginner would be much appreciated.

  • 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-06T09:14:00+00:00Added an answer on June 6, 2026 at 9:14 am

    Use TransactionScope class

    try
    {
        // Encapsulate your data access code in this using
        using (TransactionScope scope = new TransactionScope())
        {
    
    
            .....
    
            scope.Completed();
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We're building an app, our first using Rails 3, and we're having to build
I have a text area in my form which accepts all possible characters from
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have an autohotkey script which looks up a word in a bilingual dictionary
I have an array which has BIG numbers and small numbers in it. I
I'm making a simple page using Google Maps API 3. My first. One marker
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I am trying to understand how to use SyndicationItem to display feed which is

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.