数据库更改后刷新DataGridView? [英] Refreshing a DataGridView after DB has changed?
本文介绍了数据库更改后刷新DataGridView?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
中的表单DataGridView启动时正确加载DataGridView ...
但是如果DataBase中的数据更改,如何刷新它以反映新的记录或更新?
这是我在代码中做的,在网上查找一些例子之后:
MyTabBindingSource.EndEdit()
Me.MyTableAdapter.ClearBeforeFill = True
Me.MyTableAdapter.Fill Me.MyDataSet.MyTable)
MyDataGridView.Update()
MyDataGridView.Refresh()
但没有改变...我需要刷新/重绘TabControl以及包含它的表单?或者还有什么?
解决方案
我这样做的方式是清除DataGridView的DataSource,然后重新绑定。 >
尝试:
MyDataGridView.DataSource = Nothing
MyDataGridView.Rows.Clear
MyDataGridView .DataSource = MyTable?
I need to "refresh" a DataGridView, bound to a database table, on a form within a TabControl The DataGridView is loaded correctly on startup... But if the data in the DataBase change, How do I refresh it to reflect new records or updates?
this is what I am doing in code, after looking for some examples on the web:
MyTabBindingSource.EndEdit()
Me.MyTableAdapter.ClearBeforeFill = True
Me.MyTableAdapter.Fill(Me.MyDataSet.MyTable)
MyDataGridView.Update()
MyDataGridView.Refresh()
but nothing changes at all...Do I need to refresh/repaint the TabControl as well as the Form containing it? or what else??
解决方案
The way I do this is I clear the DataGridView's DataSource then re-bind it again.
Try:
MyDataGridView.DataSource = Nothing
MyDataGridView.Rows.Clear
MyDataGridView.DataSource = MyTable?
这篇关于数据库更改后刷新DataGridView?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文