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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T02:34:02+00:00 2026-05-14T02:34:02+00:00

I’ve MS Access db, datagridview that displays items, two checkbox columns that represents Yes/No

  • 0

I’ve MS Access db, datagridview that displays items, two checkbox columns that represents Yes/No columns in the db, and refresh/del buttons.

When I try to delete a row that its checkboxes hasn’t been modified, the row delets just fine, also when I modify the checkbox value, press refresh button, then delete, the row deletes fine too.

However when I try to delete a row right after modifying its checkbox value, I get concurrency violation exception error.

When checkbox value changed code:

private void dataGridView1_CellValueChanged(object sender, DataGridViewCellEventArgs e)
    {

        if (dataGridView1.Columns[e.ColumnIndex].Name == "sales")
        {

            DataGridViewCheckBoxCell checkCell = (DataGridViewCheckBoxCell)dataGridView1.Rows[e.RowIndex].Cells["sales"];
            bool _pSale = (Boolean)checkCell.Value;

            string connstring = string.Format(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0}", Path.Combine(Directory.GetCurrentDirectory(), "MyDatabase01.accdb"));
            OleDbConnection conn = new OleDbConnection(connstring);
            conn.Open();

            string sqlqry = "UPDATE Items SET pSale = " + _pSale + " WHERE p_Name = '" + this._pName + "'";
            OleDbCommand upd = new OleDbCommand(sqlqry, conn);
            upd.ExecuteNonQuery();
            conn.Close();
            //dataGridView1.Invalidate();

        }
}

Refresh button code:

public void Refreshdgv()
        {
            this.categoriesItemsBindingSource.EndEdit();
            this.itemsTableAdapter.Fill(myDatabase01DataSet.Items);
            this.dataGridView1.Refresh();
        }

Delete button code:

private void delBtn_Click(object sender, EventArgs e)
    {
            try
            {

                int cnt = dataGridView1.SelectedRows.Count;
                for (int i = 0; i < cnt; i++)
                {
                    if (this.dataGridView1.SelectedRows.Count > 0)
                    {
                        this.dataGridView1.Rows.RemoveAt(this.dataGridView1.SelectedRows[0].Index);
                    }
                }


                this.Validate();
                this.categoriesItemsBindingSource.EndEdit();
                this.itemsTableAdapter.Update(this.myDatabase01DataSet.Items);
                this.myDatabase01DataSet.AcceptChanges();

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
    }

To resolve this issue I can call Refreshdgv() method in place of dataGridView1.Invalidate(). But I don’t want the dgv refresh for each checkbox click!

  • 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-14T02:34:02+00:00Added an answer on May 14, 2026 at 2:34 am

    The delete command of your DataSet is likely checking the original values. Since you are updating your database manually in the CellValueChanged event, the values in your database won’t match the original values in your DataSet. If you modify the CellValueChanged event to use the update command in your DataSet, the values should match up when you call Delete.

    Alternatively, you could change your delete command to use a less exclusive where clause (e.g., WHERE KeySegment0 = @keySegment0 AND KeySegment1 = @keySegment1 ...).

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

Sidebar

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.