Ejemplo n.º 1
0
        // Cancel button
        private void cancelButton_Click(object sender, EventArgs e)
        {
            // Discard any changes made
            dataTable.RejectChanges();

            // Dispose of the transaction
            transaction.Dispose();
            transaction = null;

            // Turn edit mode off
            SetEditMode(false);
        }
Ejemplo n.º 2
0
        // Edit/Save button
        private void editSaveButton_Click(object sender, System.EventArgs e)
        {
            if (transaction == null)
            {
                // Begin a transaction
                try
                {
                    transaction = connection.BeginTransaction();
                }
                catch (Exception exception)
                {
                    MessageBox.Show(GetExceptionMessage(exception) + " - exiting", Text, MessageBoxButtons.OK);
                    Close();
                    return;
                }

                dataAdapter.SelectCommand.Transaction = transaction;

                // Enable conflict detection on the transaction
                transaction.BeginConflictDetection();

                // Turn edit mode on
                SetEditMode(true);
            }
            else
            {
                // If changes have been made, commit them to the database
                if (dataTable.GetChanges() != null)
                {
                    try
                    {
                        dataAdapter.Update(dataTable);
                        transaction.Commit();
                        dataTable.AcceptChanges();
                    }
                    catch (Exception exception)
                    {
                        MessageBox.Show(GetExceptionMessage(exception), Text);

                        // Discard any changes made
                        dataTable.RejectChanges();
                    }
                }

                // Dispose of the transaction
                transaction.Dispose();
                transaction = null;

                // Turn edit mode off
                SetEditMode(false);
            }
        }