using c# and vs2005
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
[code=cpp]
//code
public void GridRefresh()
{
try
{
OleDbConnection con = new OleDbConnection (strConnectionS tring);
string strSql = "SELECT * FROM tblWMLog";
OleDbDataAdapte r ABMSadapter = new OleDbDataAdapte r(strSql, strConnectionSt ring);
con.Open();
DataSet ABMSdataset = new DataSet();
OleDbCommandBui lder cmdbuilder = new OleDbCommandBui lder(ABMSadapte r);
ABMSadapter.Fil l(ABMSdataset," tblWMLog");
bsource.DataSou rce = ABMSdataset.Tab les["tblWMLog"];
dgvDetector.Dat aSource = bsource;
con.Close();
}
catch (OleDbException ex)
{
MessageBox.Show (ex.Message);
}
}
//code for databse insert
public void UpdateLog(strin g WMAgent,DateTim e WMDateTime,doub le WMDuration)
{
try
{
OleDbConnection con = new OleDbConnection (strConnectionS tring);
string insert = "INSERT INTO tblWMlog(WMID,W MDateTime,WMDur ation,Frequency ,SName)"
+ "VALUES('" + WMAgent + "','" + WMDateTime + "','" + WMDuration + "','" + Convert.ToDoubl e(config.txtSFr eq.Text) + "','" + config.txtSName .Text + "')";
OleDbCommand command = new OleDbCommand(in sert, con);
con.Open();
command.Execute NonQuery();
con.Close();
GridRefresh();
//ABMSadapter.Fil l(ABMSdataset);
//this.dgvDetecto r.DataSource = ABMSdataset.Tab les[0];
//con.Close();
//this.dgvDetecto r.Rows.Add(1, WMAgent, WMDateTime, WMDuration, Convert.ToDoubl e(config.txtSFr eq.Text), config.txtSName .Text);
//this.dgvDetecto r.Refresh();
}
catch (OleDbException ex)
{
MessageBox.Show (ex.Message);
}
}[/code]
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
[code=cpp]
//code
public void GridRefresh()
{
try
{
OleDbConnection con = new OleDbConnection (strConnectionS tring);
string strSql = "SELECT * FROM tblWMLog";
OleDbDataAdapte r ABMSadapter = new OleDbDataAdapte r(strSql, strConnectionSt ring);
con.Open();
DataSet ABMSdataset = new DataSet();
OleDbCommandBui lder cmdbuilder = new OleDbCommandBui lder(ABMSadapte r);
ABMSadapter.Fil l(ABMSdataset," tblWMLog");
bsource.DataSou rce = ABMSdataset.Tab les["tblWMLog"];
dgvDetector.Dat aSource = bsource;
con.Close();
}
catch (OleDbException ex)
{
MessageBox.Show (ex.Message);
}
}
//code for databse insert
public void UpdateLog(strin g WMAgent,DateTim e WMDateTime,doub le WMDuration)
{
try
{
OleDbConnection con = new OleDbConnection (strConnectionS tring);
string insert = "INSERT INTO tblWMlog(WMID,W MDateTime,WMDur ation,Frequency ,SName)"
+ "VALUES('" + WMAgent + "','" + WMDateTime + "','" + WMDuration + "','" + Convert.ToDoubl e(config.txtSFr eq.Text) + "','" + config.txtSName .Text + "')";
OleDbCommand command = new OleDbCommand(in sert, con);
con.Open();
command.Execute NonQuery();
con.Close();
GridRefresh();
//ABMSadapter.Fil l(ABMSdataset);
//this.dgvDetecto r.DataSource = ABMSdataset.Tab les[0];
//con.Close();
//this.dgvDetecto r.Rows.Add(1, WMAgent, WMDateTime, WMDuration, Convert.ToDoubl e(config.txtSFr eq.Text), config.txtSName .Text);
//this.dgvDetecto r.Refresh();
}
catch (OleDbException ex)
{
MessageBox.Show (ex.Message);
}
}[/code]
Comment