【问题标题】:Unable to refresh DataGridView after updating database更新数据库后无法刷新 DataGridView
【发布时间】:2014-03-28 08:43:45
【问题描述】:

我在 Visual Studio 2013 中创建了拖放 DataGridView,然后使用向导将其绑定到数据集。 我的问题是当我更新数据库中的数据时,DataGridView 没有被刷新。

我使用过这段代码:同一个表单的文本框的数据绑定如何刷新和更新。

dataGridView1.Refresh(); 

dataGridView.Update(); 

编辑: 此代码也不起作用:

private void toolStripButton4_Click(object sender, EventArgs e)
    {
        bindingSource1.ResetBindings(true);                                 
    }

【问题讨论】:

标签: c# .net winforms datagridview


【解决方案1】:

以下代码为我编写,首先您应该在数据集上调用 GetChanges() 方法,然后在 dta 适配器上调用 Fill(dataset.dataTable)。

            secaloFormulaDataSet.GetChanges();
            materialPriceTableAdapter.Fill(secaloFormulaDataSet.materialPrice);

这将立即更新您的 datagridview 和其他在表单中使用数据绑定的控件。

【讨论】:

    猜你喜欢
    • 2011-09-13
    • 2012-04-25
    • 2021-10-01
    • 2012-06-08
    • 2010-09-20
    • 1970-01-01
    • 2016-07-25
    • 2020-04-26
    相关资源
    最近更新 更多