Click here to Skip to main content
15,124,736 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.

C#
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.........
Posted
Updated 19-Jul-21 21:48pm
v2

You should reverse your calls here

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


AcceptChanges marks all rows in the ds as umodified so Update would see no changed rows to update.
   
https://www.thepenrosecondos.sg/
   

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