Click here to Skip to main content
15,881,882 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi, i have a disconnected ado.net code. I am deleting some rows from a datatable. And then acceptchanges over datatable and then update for physically saving over dataadapter. If i don't put following line everything works fine otherwise there is no actual change on database: ds.Tables[0].AcceptChanges();
I wonder why accepting changes and then updating doesnt work.

SqlConnection conn = new SqlConnection(connectionString);
            conn.Open();
            SqlDataAdapter adapter = new SqlDataAdapter("select * from People", conn);
            SqlCommandBuilder cb = new SqlCommandBuilder(adapter);
            DataSet ds = new DataSet();

            adapter.Fill(ds);

            DataRow[] rows_filtered = ds.Tables[0].Select("cityID=1");
            foreach (DataRow item in rows_filtered)
            {
                item.Delete();
            }

            dataGridView1.DataSource = ds.Tables[0];
            //ds.Tables[0].AcceptChanges(); ***why this line causes trouble***
           adapter.Update(ds.Tables[0]);


What I have tried:

Not much yet. I am really confused about adapter.Update and datatable.AcceptChanges(). They seeem to be similar.
Posted
Updated 21-Apr-19 7:18am

"AcceptChanges" comes AFTER "Update".

DataTable.AcceptChanges Method (System.Data) | Microsoft Docs[^]
 
Share this answer
 
Ok brother i see. Thank you for your reply.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900