如何将dataset.acceptchanges()保存到数据库 [英] How to save the dataset.acceptchanges( ) to database

查看:126
本文介绍了如何将dataset.acceptchanges()保存到数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hai ....
我正在更新数据集的行并通过使用ds.acceptchanges()方法保存更改的行.它正在更改数据集,但是我只需要将数据集的更新行保存到数据库....所以我正在使用这样的代码,但是它没有对数据库进行任何更改.

Hai....
I am updating the rows of dataset and saving the changed rows by using ds.acceptchanges() method. It is making changes in Dataset, But i have to save only the updated rows of dataset to Database.... So i am using the code like this, but it did not make any changes to database.

adap = new SqlDataAdapter("select * from customer1", con);
ds = new DataSet();
adap.Fill(ds);
SqlCommandBuilder cb = new SqlCommandBuilder(adap);
foreach (DataRow dr in ds.Tables[0].Rows)
{
if (dr[0].ToString() == TextBox1.Text)//text box have data of first column of a row
{
dr[1] = TextBox2.Text;//text box have data of second column of a row
dr[2] = TextBox3.Text;//text box have data of third column of a row
} 
}
ds.AcceptChanges();
adap.Update(ds);
GridView1.DataSource = ds;
GridView1.DataBind();



谁能帮助我我错了......
谢谢.........



Can anybody help me where i was wrong....
Thanks.........

推荐答案

您应该在此处转接电话

You should reverse your calls here

adap.Update(ds);
ds.AcceptChanges();



AcceptChanges将ds中的所有行标记为未修改,因此Update不会看到要更新的更改行.



AcceptChanges marks all rows in the ds as umodified so Update would see no changed rows to update.


这篇关于如何将dataset.acceptchanges()保存到数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆