Bound radgridview delete row problem

3 Answers 83 Views
GridView
Chris
Top achievements
Rank 2
Iron
Chris asked on 20 Sep 2022, 06:08 PM

Hi all,

When inserting a row everything goes okay.
But when I delete that same row again using the radgridview contextmenu option Delete Row

Then the debugger shows the following error massage:
'System.Data.DBConcurrencyException: 'Concurrency violation: the DeleteCommand affected 0 of the expected 1 records.''

My code is below.

What am I doing wrong?

Chris.

 public partial class mainForm : Form
    {

        public static OleDbConnection con3 = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source = " + Application.StartupPath + "\\parts.accdb");
        public static DataTable dt = new DataTable();
        public OleDbDataAdapter adapter;
        public OleDbCommandBuilder commandbuider;
        public mainForm()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            string SQL = "SELECT * from supplier";
            adapter = new OleDbDataAdapter(SQL, con3);
            commandbuider = new OleDbCommandBuilder(adapter);

            adapter.Fill(dt);

            PartsGrid.DataSource = dt;

            PartsGrid.RowsChanged  += new GridViewCollectionChangedEventHandler(PartsGrid_Update);

        }

        private void PartsGrid_Update(object sender, GridViewCollectionChangedEventArgs e)
        {
            if (adapter.Update(dt) > 0)
            {
                MessageBox.Show("done");
            }
        }
    }

 

3 Answers, 1 is accepted

Sort by
0
Dinko | Tech Support Engineer
Telerik team
answered on 22 Sep 2022, 10:12 AM

Hi Chris,

Thank you for the provided code snippet.

I am not exactly sure why this error appears. I have performed some tests but wasn't able to reproduce this error. You could check the Updating of the database on row added/deleted or when the current row is changed section for a possible way to update the database when a row is added/deleted. Give it a try and let me know if this exception occurs again.

Regards,
Dinko | Tech Support Engineer
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Chris
Top achievements
Rank 2
Iron
commented on 26 Sep 2022, 01:36 PM

Hi Dinko,

I can't get it to work.

Can you give me an example with my code?

 

Regards,
Chris.

0
Dinko | Tech Support Engineer
Telerik team
answered on 27 Sep 2022, 10:02 AM

Hello Chris,

To be able to assist I will need to reproduce this. For this purpose, I have created a sample project which used your code. So far if I delete a row, no exception occurs. Could it be possible to modify the project to reproduce this exception and send it back? This way I could take a closer look and debug it.

I am looking forward to your reply.

As a side note, the access database is located in the project. You can change the path to your folder location.

Regards,
Dinko | Tech Support Engineer
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

0
Chris
Top achievements
Rank 2
Iron
answered on 04 Oct 2022, 09:42 AM
I finaly solved the problem, when I rebind the database then I have no problems with delete rows anymore.
private void PartsGrid_Update(object sender, EventArgs e)
        {
            if (adapter.Update(dt) > 0)
            {
               dt.Clear() ;
                string SQL = "SELECT * from supplier";
                adapter = new OleDbDataAdapter(SQL, con3);
                commandbuider = new OleDbCommandBuilder(adapter);
                adapter.Fill(dt);
                PartsGrid.DataSource = dt;
                MessageBox.Show("done");
            }
        }

Dess | Tech Support Engineer, Principal
Telerik team
commented on 04 Oct 2022, 12:20 PM

Chris, it is good to hear that you have found an appropriate solution for your case. In case you experience any further difficulties again, it would be good to have a runnable sample project demonstrating the problem you are facing. Thus, we would be able to make an adequate analysis of the precise case and provide further assistance.
Tags
GridView
Asked by
Chris
Top achievements
Rank 2
Iron
Answers by
Dinko | Tech Support Engineer
Telerik team
Chris
Top achievements
Rank 2
Iron
Share this question
or