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
-
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);
-
}
-
-
-
}
3 4806
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
Just makes it easier to read. :)
i dint understand ur answer
@aleesha
Add this line of code after you rebind the grid. -
bSource.ResetBindings(false)
-
This will force the control to re-read all the items in the list. You can read more about this method here Sign in to post your reply or Sign up for a free account.
Similar topics |
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...
|
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,
|
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()
|
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...
|
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...
| |
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...
|
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...
|
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
|
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
|
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...
|
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...
| |
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,...
|
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...
|
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...
|
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...
|
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...
|
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();...
| |
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
|
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...
| |