简体   繁体   中英

DataBinding between DataSet and DataGridView in C#

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,您必须在DataSet上调用GetChanges ,然后插入/更新/删除记录。

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!

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