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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T20:44:43+00:00 2026-05-27T20:44:43+00:00

On a button click I am saving info to a Sqlite database. I have

  • 0

On a button click I am saving info to a Sqlite database. I have the command.ExecuteNonQuery() in a try block. I have got everything handled just find if the catch block is caught, but if everything makes it through just fine I want other code to execute that would clear out the values of my EditTexts and set focus. I try putting that code after the ExecuteNonQuery() in my try block, but it still executes before the catch block even if an exception is caught so the values of my edittexts get cleared out before the catch block can even do anything. Same story if I add the code after my try/catch block entirely. The catch block seems to be the last thing executing and by then the values have been cleared and the catch block can’t even execute properly. How do I set the values to clear only after the catch block is cleared and no exceptions are thrown?

EDIT: Tried putting it in a finally block but the same thing. Locals window shows both partnumber.Text and partQty.text are blank by the time they get to the catch block. But if I take out the code that clears those fields then both still have their values in the catch block. Is there something special maybe about Sqlite exceptions that would create a timing issue?

        try
    {
        c.ExecuteNonQuery();
        partnumber.Text = "";
        partqty.Text = "";
        partnumber.RequestFocus();
    }
    catch (SqliteException ex)
    {
        if (ex.ErrorCode.ToString() == "Constraint")
        {
            AlertDialog.Builder builder = new AlertDialog.Builder(this);
            builder.SetTitle("Item Duplication");
            builder.SetMessage("You have already counted this item.  How would you like to proceed?");
            builder.SetPositiveButton("Add to Previous", delegate
            {
                var newQty = Convert.ToInt32(test.currQuantity(partnumber.Text)) + Convert.ToInt32(partqty.Text);
                var n = connection.CreateCommand();
                connection.Open();
                n.CommandText = "Update [Items] Set Quantity = '" + newQty.ToString() + "' Where ItemNmbr = '" + partnumber.Text + "'";
                n.ExecuteNonQuery();
                Toast.MakeText(this, "Quantity updated to: " + newQty.ToString(), ToastLength.Long)
                    .Show();
                partnumber.Text = "";
                partqty.Text = "";
                partnumber.RequestFocus();
                connection.Close();
                return;
            });
            builder.SetNegativeButton("Override Previous", delegate
            {
                var n = connection.CreateCommand();
                connection.Open();
                n.CommandText = "Update [Items] Set Quantity = '" + partqty.Text + "' Where ItemNmbr = '" + partnumber.Text + "'";
                n.ExecuteNonQuery();
                Toast.MakeText(this, "Quantity updated to: " + test.currQuantity(partnumber.Text), ToastLength.Long)
                    .Show();
                partnumber.Text = "";
                partqty.Text = "";
                partnumber.RequestFocus();
                connection.Close();
                return;
            });
            var dialog = builder.Create();
            dialog.Show();
        }
        else
        {
            AlertDialog.Builder builder = new AlertDialog.Builder(this);
            builder.SetTitle("Error");
            builder.SetMessage(ex.Message.ToString());
            var dialog = builder.Create();
            dialog.Show();
        }
    }
  • 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-27T20:44:44+00:00Added an answer on May 27, 2026 at 8:44 pm

    You could try putting them in a finally block.

    try {/*execute code*/}
    catch(System.Exception e){/*handle exceptions*/}
    finally {/*clean up regardless if an exception was thrown or not*/}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

On click of a button, I am saving the record to the database. I
Currently I have a command that does this. First, upon the button click event
I have a button click event that takes information from controls and enters it
I've got this code in a pair of button click event handlers on a
In the jQuery 'ready' block, I have: // bind print work order button to
I have a button which launches a modal dialog - it just creates a
I am saving records on save button click, if user don't click save button
In a web page button click event we need to export 2,00,000 to 5,00,000
Lets say for example: $(.button).click(function() { $.post(commandrunner.php, { param1: 'value', param2: 'value2', param3: 'value3'
I am using UpdatePanel to trigger a button click event, which saves some 100+

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.