我创建了用于在pc(公司中的500台计算机)之间发送消息的项目(.NET 3.5)。如何在MySql添加新行时重新加载datagridview? 谁可以帮我解决DBMS问题? 或者我应该寻求其他解决方案? 这是我的代码:
private void Form1_Load(object sender, EventArgs e)
{
FillData();
}
public void FillData()
{
using (MySqlConnection myConnection =
new MySqlConnection("Server=10.7.18.35;Database=OitDB;Uid=martin;Pwd=;"))
{
myConnection.Open();
using (MySqlDataAdapter sqlDa = new MySqlDataAdapter(
"select * from nrp", myConnection))
{
DataTable dt = new DataTable();
sqlDa.Fill(dt);
dataGridView1.DataSource = dt;
this.dataGridView1.Refresh();
dataGridView1.Columns[0].Width = 125;
dataGridView1.Columns[1].Width = 500;
dataGridView1.Columns[2].Width = 125;
dataGridView1.AllowUserToAddRows = false;
dataGridView1.FirstDisplayedScrollingRowIndex = dataGridView1.RowCount - 1;
}
}
}