C# Winforms DataTableAdapter 数据绑定问题
我有一个用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您是否尝试在加载表单时显式调用
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.
我的建议/评论可能不符合您的条件,但是参考这个问题,请注意,您还可以修改
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 callUpdate
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 setDataSource
again.