DataBinding between DataSet and DataGridView in C#(C#中DataSet和DataGridView之间的数据绑定)
问题描述
我目前在表单上有一个 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之间的数据绑定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:C#中DataSet和DataGridView之间的数据绑定
基础教程推荐
- 从 VS 2017 .NET Core 项目的发布目录中排除文件 2022-01-01
- 错误“此流不支持搜索操作"在 C# 中 2022-01-01
- 如何动态获取文本框中datagridview列的总和 2022-01-01
- 在 VS2010 中的 Post Build 事件中将 bin 文件复制到物 2022-01-01
- 将事件 TextChanged 分配给表单中的所有文本框 2022-01-01
- 是否可以在 asp classic 和 asp.net 之间共享会话状态 2022-01-01
- 经典 Asp 中的 ResolveUrl/Url.Content 等效项 2022-01-01
- JSON.NET 中基于属性的类型解析 2022-01-01
- 首先创建代码,多对多,关联表中的附加字段 2022-01-01
- 全局 ASAX - 获取服务器名称 2022-01-01
