DataBinding between DataSet and DataGridView in C#

馋奶兔 提交于 2019-12-23 05:14:21

问题


I currently have a DataGridView on a form which I want to use with a DataTable in a DataSet, populated from a SQlite database (using System.Data.SQlite).

So, I have a DataAdapter between the database and DataSet and can set the DataGridView data source directly as the DataTable. This displays fine.

My question is this: Why would I want to use a Binding Source here? Many tutorials have said you can use it or not. But is there any use for it, other than adding an extra step?

Also, if I want the database to be updated when the DataGridView is changed, how can this be done? Is the DataSet automatically updated - so I just need to tell the DataAdapter to update? Or is there where a binding source is useful?

Thanks!


回答1:


AFAIK, you would have to call GetChanges on the DataSet, and then insert/update/delete the records.




回答2:


For anyone else searching for this, I found a good description of why to use a Binding Source here.

Similarly, this explains saving/restoring changes made in the DataGridView.

Hope that helps someone!



来源:https://stackoverflow.com/questions/4791572/databinding-between-dataset-and-datagridview-in-c-sharp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!