[英]How to refresh after inserting data into database?
我是C#的新手。 在將數據插入數據庫之后,我有一個表格可以讓我查看我的數據,其中DataGridView
將顯示所有數據。 但是,該表不會顯示正在插入數據庫的新數據。
研究了datagridview.refresh()
但它只是圖形刷新。
以下是我的代碼:( 不知道我是否在正確的軌道上)
private void button_refresh_Click(object sender, EventArgs e)
{
//DataGridView1.refresh();
//DataSet1.GetChanges();
//TableAdapter.Fill(DataSet1.table);
}
如果您不使用數據綁定,那么唯一的方法是刪除所有行:
DataGridView1.Rows.Clear();
然后像最初一樣閱讀並再次添加行
假設d是我擁有的DataSource
d.Add(new string[] {"a", "b", "c"});
dataGridView1.DataSource = d;
現在我的DataGridView有1行
過了一會兒 ...
d.Add(new string[] { "1", "2", "3" });
d.Add(new string[] { "4", "5", "6" });
d.Add(new string[] { "x", "y", "z" });
dataGridView1.DataSource = null;
dataGridView1.DataSource = d;
dataGridView1.Refresh();
現在我的DataGridView有4行。
this.employeesTableAdapter.Fill(this.dataSet1.Employees);
Where: Employees your table
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.