问题描述
我目前在表单上有一个 DataGridView,我想将它与 DataSet 中的 DataTable 一起使用,从 SQlite 数据库填充(使用 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).
所以,我在数据库和DataSet之间有一个DataAdapter,可以直接将DataGridView数据源设置为DataTable.这显示正常.
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?
另外,如果我希望在 DataGridView 更改时更新数据库,该怎么做?DataSet 是否自动更新 - 所以我只需要告诉 DataAdapter 更新?或者绑定源在哪里有用?
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?
谢谢!
推荐答案
对于搜索此内容的其他人,我找到了一个很好的说明,说明了为什么要使用绑定源 这里.
For anyone else searching for this, I found a good description of why to use a Binding Source here.
同样,this 解释了保存/恢复在 DataGridView 中所做的更改.
Similarly, this explains saving/restoring changes made in the DataGridView.
希望对某人有所帮助!
这篇关于C#中DataSet和DataGridView之间的数据绑定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!