本文介绍了Dataadapter.update()不保存任何内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个断开连接的ado.net代码。我正在从数据表中删除一些行。然后接受对数据表的更改,然后更新以通过dataadapter进行物理保存。如果我没有放下一行,一切正常,否则数据库上没有实际的变化:ds.Tables [0] .AcceptChanges();

我想知道为什么接受更改然后更新不起作用。



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]);





我尝试过:



还不多。我对adapter.Update和datatable.AcceptChanges()感到困惑。他们看起来很相似。



What I have tried:

Not much yet. I am really confused about adapter.Update and datatable.AcceptChanges(). They seeem to be similar.

推荐答案



这篇关于Dataadapter.update()不保存任何内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-29 22:52