简体   繁体   中英

reflecting changes made to the datagrid back on the dataset and the datatable

i have a datagrid which has a dataset as its datasource and that dataset contains a table from a database.what i need is when i make changes to cell values in datagrid, the changes should also reflect back on the database. the thing is these changes do get reflected on the dataset but when i use da.Update(ds,"TableName") to forward that changes to database,it does not work. The database still shows the old value even though the datagrid and dataset shows the updated value. i have used the da.Update() command twice in the same program at other places and there it seems to work properly and the database shows the updated value. i dont know wats causing it to not work this time. wats suprising is that i am not even getting any errors, the code executes properly but no changes are seen in the database. someone kindly help!!!

edit: actually, what i am doing is i am selecting a row from a datagrid and then displaying all the cell values from that row on textboxes. then i am editing those values and saving them using foll. code

private void btnSave_Click(object sender, EventArgs e) { dgDetails.SelectedCells[0].Value = txtPurpose.Text; da.Update(ds, "Scheduler"); }

no one has the solution for the problem????

Are you using the same data adapter for both the fill and the update method call? I believe that for the most part you need to call the fill and update methods from the same data adapter.

Also, make sure you're not calling AcceptChanges before calling Update. AcceptChanges will change the state of the dataset to unchanged.

There's a good example of accomplishing what you're looking to do at http://www.developerfusion.com/article/3801/web-forms-datagrid-and-dataset-programming/6/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM