[英]How to refresh after inserting data into database?
I am new to c#. 我是C#的新手。 After inserting data into my database, i have a form which allows me to view my data where the
DataGridView
would display all the data. 在将数据插入数据库之后,我有一个表格可以让我查看我的数据,其中
DataGridView
将显示所有数据。 However, the table does not display the new data that is being inserted into the database. 但是,该表不会显示正在插入数据库的新数据。
Have researched on datagridview.refresh()
but its only graphical refresh. 研究了
datagridview.refresh()
但它只是图形刷新。
Following is my code: (No idea whether I'm on the right track or not) 以下是我的代码:( 不知道我是否在正确的轨道上)
private void button_refresh_Click(object sender, EventArgs e)
{
//DataGridView1.refresh();
//DataSet1.GetChanges();
//TableAdapter.Fill(DataSet1.table);
}
If you are not using data binding then the only way is to remove all the rows: 如果您不使用数据绑定,那么唯一的方法是删除所有行:
DataGridView1.Rows.Clear();
and then read and add rows again as you did initially 然后像最初一样阅读并再次添加行
let's imagine d is the DataSource
I have 假设d是我拥有的
DataSource
d.Add(new string[] {"a", "b", "c"});
dataGridView1.DataSource = d;
Now my DataGridView has 1 row 现在我的DataGridView有1行
after a while ... 过了一会儿 ...
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();
Now my DataGridView has 4 rows. 现在我的DataGridView有4行。
this.employeesTableAdapter.Fill(this.dataSet1.Employees);
Where: Employees your table
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.