开发者

DataBinding between DataSet and DataGridView in C#

开发者 https://www.devze.com 2023-02-06 08:40 出处:网络
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).

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!


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


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!

0

精彩评论

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

关注公众号