开发者

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

开发者 https://www.devze.com 2022-12-18 03:53 出处:网络
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

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 th开发者_StackOverflow社区e 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/

0

精彩评论

暂无评论...
验证码 换一张
取 消