C# Winforms DataTableAdapter 数据绑定问题

发布于 2024-10-03 18:05:51 字数 400 浏览 3 评论 0原文

我有一个用 C# 编写的应用程序。 来自数据库的记录通过自动生成的 Visual Studio 代码 (DataTableAdapter) 显示。

this._______tTableAdapter.Fill(this._______SQLDataSet._______);

现在,当我对数据库进行更改时,不是通过 DataTableAdaper,而是通过另一个 winform 上的代码,关闭它并打开另一个我用适配器填充 DataTable 的地方,直到我重新启动应用程序后,更改才会显示。 我不明白,我尝试使用 this.Close() 和 this.Dispose() 关闭窗口以释放所有资源,因此下次打开它时,代码应该重新绑定数据库中的新数据,但是事实并非如此... 我做错了什么? 非常感谢您的任何答复...

I have an app written in c#.
Records from the DB are shown through the auto-generated visual studio code (DataTableAdapter).

this._______tTableAdapter.Fill(this._______SQLDataSet._______);

Now, when I make changes to the DB, not through the DataTableAdaper - but through code on another winform, close it and open another where I have my DataTable filled with adapter, the changes are not shown until I restart my app.
I don't get it, I tryed closing the window using this.Close() and this.Dispose() to release all the resources, so the next time I open it, the code should rebind the new data from the database, but that's not the case...
What am I doing wrong?
Thanks very much for any anwser...

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

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

发布评论

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

评论(2

多情癖 2024-10-10 18:05:51

您是否尝试在加载表单时显式调用 DataGridView.Rows.Clear()

如果这不起作用,请在调试模式下加载表单,并查看每一步数据的状态。

Have you tried explicitly calling DataGridView.Rows.Clear() when you are loading the form?

If that doesn't work, load the form in debug mode, and look at the status of the data every step of the way.

陌路黄昏 2024-10-10 18:05:51

我的建议/评论可能不符合您的条件,但是参考这个问题,请注意,您还可以修改DataSet中的数据(而不是每次更改都将计算传递到服务器上)。如果进行了所有更改 - 您可以在数据适配器上调用 Update 方法,该方法为所有更改的行提供数据更新。
无论如何 - 如果您只想刷新在其他实例中所做的更改 - 只需刷新 DataGridView 或再次设置 DataSource 即可。

My suggestion/comment may not meet your conditions, but referring to this problem, notice, that you can also modify data in DataSet (not passing the calculations on the server witch every change). If all changes are made - you can call Update method on data adapter which provide data updates for all changed rows.
Anyway - if you want only refresh changes made in other instance - just refrech DataGridView or set DataSource again.

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