【问题标题】:dataGridView not updating c#?dataGridView 不更新 c#?
【发布时间】:2013-05-04 14:23:24
【问题描述】:

我已经使用下面的代码填充了datagridView

    this.empinfoTableAdapter1.Fill(this.empData.empinfo);

但是当我从 gridview 更新表时,它会更新原始数据库。但未在表单中显示更新。

我搜索了谷歌并找到了类似的问题。但其中大部分是自定义数据绑定。不使用

  this.empinfoTableAdapter1.Fill(this.empData.empinfo);

所以,我发布了这个问题。

【问题讨论】:

    标签: c# datagridview


    【解决方案1】:

    如果是 ASP.Net 应用程序,则需要调用DataBind(),如:

    GridView1.DataBind();
    

    如果它的 WinForm 应用程序,那么您需要再次分配 DataSoure,例如:

    GridView1.DataSource = this.empData.empinfo;
    

    【讨论】:

    • 你的回答解决了我一半的问题。但是在更新数据后,如果我调用 dataGridView1.DataSource = this.dbDataSet.empinfo;然后 dataGridView 向我显示更新的数据。但是,如果我关闭表单并重新打开它,那么表单将填充旧数据。我猜是 empinfoTableAdapter 在我运行项目时保留数据。有没有办法刷新 enpinfoTableAdapter。
    • 不是很确定你的问题,但是TableAdapter是假设填充DataTable,如果你需要最新的记录,你需要在重新绑定之前再次调用Fill方法。
    猜你喜欢
    • 1970-01-01
    • 2012-09-26
    • 2011-07-28
    • 2017-01-04
    • 1970-01-01
    • 1970-01-01
    • 2012-10-25
    • 1970-01-01
    • 2011-07-22
    相关资源
    最近更新 更多