473,327 Members | 2,103 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

datagridview refresh

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
Expand|Select|Wrap|Line Numbers
  1. //code
  2.  public void GridRefresh()
  3.         {
  4.  
  5.             try
  6.             {
  7.                 OleDbConnection con = new OleDbConnection(strConnectionString);
  8.                 string strSql = "SELECT * FROM tblWMLog";
  9.                 OleDbDataAdapter ABMSadapter = new OleDbDataAdapter(strSql, strConnectionString);
  10.                 con.Open();
  11.                 DataSet ABMSdataset = new DataSet();
  12.                 OleDbCommandBuilder cmdbuilder = new OleDbCommandBuilder(ABMSadapter);
  13.                 ABMSadapter.Fill(ABMSdataset,"tblWMLog");
  14.                 bsource.DataSource = ABMSdataset.Tables["tblWMLog"];
  15.                 dgvDetector.DataSource = bsource;
  16.  con.Close();
  17.             }
  18.             catch (OleDbException ex)
  19.             {
  20.                 MessageBox.Show(ex.Message);
  21.             }
  22.         }
  23. //code for databse insert
  24.  
  25.  public void UpdateLog(string WMAgent,DateTime WMDateTime,double WMDuration)
  26.         {
  27.             try
  28.             {
  29.                 OleDbConnection con = new OleDbConnection(strConnectionString);
  30.                 string insert = "INSERT INTO tblWMlog(WMID,WMDateTime,WMDuration,Frequency,SName)"
  31.                      + "VALUES('" + WMAgent + "','" + WMDateTime + "','" + WMDuration + "','" + Convert.ToDouble(config.txtSFreq.Text) + "','" + config.txtSName.Text + "')";
  32.                 OleDbCommand command = new OleDbCommand(insert, con);
  33.                 con.Open();
  34.                 command.ExecuteNonQuery();
  35.                 con.Close();
  36.                 GridRefresh();
  37.  
  38.                 //ABMSadapter.Fill(ABMSdataset);
  39.                 //this.dgvDetector.DataSource = ABMSdataset.Tables[0];
  40.                 //con.Close();
  41.                 //this.dgvDetector.Rows.Add(1, WMAgent, WMDateTime, WMDuration, Convert.ToDouble(config.txtSFreq.Text), config.txtSName.Text);
  42.                 //this.dgvDetector.Refresh();
  43.  
  44.             }
  45.             catch (OleDbException ex)
  46.             {
  47.                 MessageBox.Show(ex.Message);
  48.             }
  49.  
  50.  
  51.         }
Dec 18 '08 #1
3 4781
nukefusion
221 Expert 100+
Try calling ResetBindings(false) on your BindingSource.

You can also wrap your code samples in code tags, like this:

[code] code goes here [ /code]

so it looks like this

Expand|Select|Wrap|Line Numbers
  1.     // Here's my code sample
  2.  
Just makes it easier to read. :)
Dec 18 '08 #2
i dint understand ur answer
Dec 19 '08 #3
nukefusion
221 Expert 100+
@aleesha
Add this line of code after you rebind the grid.

Expand|Select|Wrap|Line Numbers
  1. bSource.ResetBindings(false)
  2.  
This will force the control to re-read all the items in the list. You can read more about this method here
Dec 19 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: RSH | last post by:
Hi, I have a situation where I have a DDL that lists all of the tables in a particular database, and a Datagridview which appears in the same from below the DDL.. When the user selects a new...
6
by: George | last post by:
Hi, I have been encountering a refresh problem with DataGridView, which is bound to a DataTable. When I make updates (Add, Delete, update) to the DataGridView, everything flow nicely to...
2
by: Ivan | last post by:
I have a class Foo which have two property. I have a thread that do some process and update class Foo int B. I have a datagridview on main form. this datagridview data source to this class Foo and...
2
by: Rick Shaw | last post by:
Hi, I have a problem with the datagridview not refreshed when the application first appear on the screen. The datagridview display data from a table in the dataset. At the same time, I've added...
3
by: David Cartwright | last post by:
Hi all, I'm having a weird time with a call to the Refresh() method of a DataGridView. I have a VB.NET 2005 Windows application with a main form and a "worker" thread. The main form delegates a...
4
by: shibeta | last post by:
Hello, I have problem with DataGridView and BindingSource. I have created DataSet and added TableData to it with manualy created columns (without DataAdapter - I'm not using MSSQL). On the Form I...
3
by: Richard Lewis Haggard | last post by:
I have a DataGridView which has a cell that is going to contain what might be a large amount of text data. The UI designed has decreed that each row will have a button that toggles the row's...
3
by: M K | last post by:
I have added a record to the underlying db and after I add the record i do a datagridview.Refresh(); and i dont see the newly added record. If i stop and start the application its there. What am...
7
by: mvenkatesan | last post by:
Hi guys I am win appl. I was bind the datagridview from datatable. i was changed datas @ runtime. datatable changed but my datagridview not refresh. I written dagaridview.refresh(); not work ...
1
by: Aegixx | last post by:
Ok, extremely wierd situation here: (I'll post the code below, after the explanation) I've got a Windows application (.NET 3.5) that has a single Form with a DataGridView embedded. The user...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.