Click here to Skip to main content
15,891,033 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.
**************************************
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

You need to call adap.UpdateCommand = cb.GetUpdateCommand() before adap.Update(ds)
 
Share this answer
 
adap.UpdateCommand = cb.GetUpdateCommand();

For this line its throwing the error like this. Pls check.....

Dynamic SQL generation for the UpdateCommand is not supported against a SelectCommand that does not return any key column information.
 
Share this answer
 
Hey Hi!!!

customer1 must have atleast one primary key column for update and delete operations using CommandBuilders. Also check command text of update command.
 
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