C# 中 DataSet 和 DataGridView 之间的数据绑定

发布于 2024-10-14 03:23:35 字数 369 浏览 8 评论 0原文

我目前在表单上有一个 DataGridView,我想将其与 DataSet 中的 DataTable 一起使用,从 SQlite 数据库填充(使用 System.Data.SQlite)。

因此,我在数据库和DataSet之间有一个DataAdapter,可以将DataGridView数据源直接设置为DataTable。这显示得很好。

我的问题是这样的: 为什么我想在这里使用绑定源?很多教程都说可以用也可以不用。但除了增加一个额外的步骤之外,它还有什么用处呢?

另外,如果我希望在 DataGridView 更改时更新数据库,该怎么办? DataSet 是否自动更新 - 所以我只需要告诉 DataAdapter 更新?或者是否有绑定源有用的地方?

谢谢!

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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

岁月苍老的讽刺 2024-10-21 03:23:35

AFAIK,您必须在 DataSet 上调用 GetChanges,然后插入/更新/删除记录。

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

小草泠泠 2024-10-21 03:23:35

对于其他搜索此内容的人,我找到了关于为什么使用绑定源的很好的描述 在这里

同样,解释了在 DataGridView 中所做的保存/恢复更改。

希望对某人有帮助!

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!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文