I am trying to refresh a datagridview control after updating a database, but despite everything
I've tried, no success.
When the app starts up, GridRefresh() is called to initially populate the dgv. This works fine.
The app then updates the database and calls GridRefresh() again expecting to see an updated row of the dgv with the updates, but no update -- just the original data.
The database is definitely being updated because if I restart the app, the dgv now has the updates.
My code is here
Expand|Select|Wrap|Line Numbers
- //code
- public void GridRefresh()
- {
- try
- {
- OleDbConnection con = new OleDbConnection(strConnectionString);
- string strSql = "SELECT * FROM tblWMLog";
- OleDbDataAdapter ABMSadapter = new OleDbDataAdapter(strSql, strConnectionString);
- con.Open();
- DataSet ABMSdataset = new DataSet();
- OleDbCommandBuilder cmdbuilder = new OleDbCommandBuilder(ABMSadapter);
- ABMSadapter.Fill(ABMSdataset,"tblWMLog");
- bsource.DataSource = ABMSdataset.Tables["tblWMLog"];
- dgvDetector.DataSource = bsource;
- con.Close();
- }
- catch (OleDbException ex)
- {
- MessageBox.Show(ex.Message);
- }
- }
- //code for databse insert
- public void UpdateLog(string WMAgent,DateTime WMDateTime,double WMDuration)
- {
- try
- {
- OleDbConnection con = new OleDbConnection(strConnectionString);
- string insert = "INSERT INTO tblWMlog(WMID,WMDateTime,WMDuration,Frequency,SName)"
- + "VALUES('" + WMAgent + "','" + WMDateTime + "','" + WMDuration + "','" + Convert.ToDouble(config.txtSFreq.Text) + "','" + config.txtSName.Text + "')";
- OleDbCommand command = new OleDbCommand(insert, con);
- con.Open();
- command.ExecuteNonQuery();
- con.Close();
- GridRefresh();
- //ABMSadapter.Fill(ABMSdataset);
- //this.dgvDetector.DataSource = ABMSdataset.Tables[0];
- //con.Close();
- //this.dgvDetector.Rows.Add(1, WMAgent, WMDateTime, WMDuration, Convert.ToDouble(config.txtSFreq.Text), config.txtSName.Text);
- //this.dgvDetector.Refresh();
- }
- catch (OleDbException ex)
- {
- MessageBox.Show(ex.Message);
- }
- }