473,769 Members | 1,637 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

datagridview refresh

2 New Member
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 4806
nukefusion
221 Recognized Expert New Member
Try calling ResetBindings(f alse) 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
aleesha
2 New Member
i dint understand ur answer
Dec 19 '08 #3
nukefusion
221 Recognized Expert New Member
@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
3150
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 database table from the list I refresh the datagridview with the newly selected tables data. This works fine but after a few tables have been selected it takes a very long time to load some of the tables. Some tables that contain only one row of...
6
50477
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 DataTable. No problem here. However, when I add data (programatically) to the DataTable, the DataGridView does not refresh right away. If I minimize and show my form,
2
5019
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 column A binds to string A and column B binds to int B. When i start two threads, the datagridview able to show two rows and updated int B at run time. How? public class Foo { public Foo()
2
8722
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 checkbox columns that are not bounded the table. This datagridview is located in the tab (2nd). I thought I mention that since that might be part of the problem (?). When the applications start, it will need some parameter criteria selection...
3
7597
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 Sub to the worker so that the latter can refresh the DataGrid after updating the DataTable driving it. When I run the app under the debugger, everything's fine. But when I run it for real, it hangs, apparently in the Refresh() method of the...
4
18710
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 put DataGridView and BindingSource, and connected them (BindingSource of course is also connected with DataSet). Next on the separated thread I'm reading data from DB and load them do DataSet (more preciselly, readed data I've saved as XML and...
3
25072
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 multiline display such that, when the button is up, the row is a single line and when the button is down, the row enters a multiline mode so that the cell can expand to a height great enough to display all of the cell's contents. I've figured out how to...
3
27950
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 I doing or not doing? Mark
7
7388
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 how to refresh? Thanks in advance Venky
1
3759
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 presses a button to do a SQL query (fill a DataSet). Before firing the query, I disable the grid/buttons and turn on UseWaitCursor. After it completes, I re-enable the grid/ buttons, refresh the dataset, then turn off the UseWaitCursor. If I...
0
9589
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9423
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10211
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10045
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9863
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8870
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6673
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
3958
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2815
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.