473,406 Members | 2,352 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,406 software developers and data experts.

Need to wait for TableAdapter.Update to finish

I have written an application that has a DataGridView for users to
amend a table. When finished they click a 'Save' button, which
generates a series of queries based on the new data. The problem is
this:

The underlying table is always updated correctly and when I step
through the code with the debugger it works perfectly, but when run it
live the events don't take account of the changes. This makes me
believe that the queries are not waiting for the update to complete.
Does this make sense? Can I do anything to make them wait?

Thanks
Apr 7 '08 #1
8 3893
Boris,

How are you updating the database, while using your save button.

Standard is this just a synchrone process.

Cor

"Boris227" <ad***********@btinternet.comschreef in bericht
news:1b**********************************@59g2000h sb.googlegroups.com...
>I have written an application that has a DataGridView for users to
amend a table. When finished they click a 'Save' button, which
generates a series of queries based on the new data. The problem is
this:

The underlying table is always updated correctly and when I step
through the code with the debugger it works perfectly, but when run it
live the events don't take account of the changes. This makes me
believe that the queries are not waiting for the update to complete.
Does this make sense? Can I do anything to make them wait?

Thanks

Apr 7 '08 #2
On 7 Apr, 12:10, "Cor Ligthert [MVP]" <notmyfirstn...@planet.nl>
wrote:
Boris,

How are you updating the database, while using your save button.

Standard is this just a synchrone process.

Cor

"Boris227" <adrian_mor...@btinternet.comschreef in berichtnews:1b**********************************@5 9g2000hsb.googlegroups.com...
I have written an application that has a DataGridView for users to
amend a table. When finished they click a 'Save' button, which
generates a series of queries based on the new data. *The problem is
this:
The underlying table is always updated correctly and when I step
through the code with the debugger it works perfectly, but when run it
live the events don't take account of the changes. This makes me
believe that the queries are not waiting for the update to complete.
Does this make sense? Can I do anything to make them wait?
Thanks- Hide quoted text -

- Show quoted text -
Me.Validate()
Me.dgvDiagadd.EndEdit()
Try
Me.DiagAddTableAdapter.Update(Me.Visir_RTDS_v3Data Set3)
Catch
MessageBox.Show("An error occurred during the update
process")
Finally
strSQL = "INSERT INTO tbl1 (a, b, c) SELECT etc ....... ;"
db.DoCmd.RunSQL(strSQL)
MessageBox.Show("Save completed")
End Try
Apr 7 '08 #3
On 7 Apr, 12:51, Boris227 <adrian_mor...@btinternet.comwrote:
On 7 Apr, 12:10, "Cor Ligthert [MVP]" <notmyfirstn...@planet.nl>
wrote:


Boris,
How are you updating the database, while using your save button.
Standard is this just a synchrone process.
Cor
"Boris227" <adrian_mor...@btinternet.comschreef in berichtnews:1b**********************************@5 9g2000hsb.googlegroups.com...
>I have written an application that has a DataGridView for users to
amend a table. When finished they click a 'Save' button, which
generates a series of queries based on the new data. *The problem is
this:
The underlying table is always updated correctly and when I step
through the code with the debugger it works perfectly, but when run it
live the events don't take account of the changes. This makes me
believe that the queries are not waiting for the update to complete.
Does this make sense? Can I do anything to make them wait?
Thanks- Hide quoted text -
- Show quoted text -

Me.Validate()
Me.dgvDiagadd.EndEdit()
Try
* * * * Me.DiagAddTableAdapter.Update(Me.Visir_RTDS_v3Data Set3)
Catch
* * * * *MessageBox.Show("An error occurred during the update
process")
Finally
* * * * strSQL = "INSERT INTO tbl1 (a, b, c) SELECT etc ....... ;"
* * * * db.DoCmd.RunSQL(strSQL)
* * * * MessageBox.Show("Save completed")
End Try- Hide quoted text -

- Show quoted text -
My current work around is to provide a second button for all the SQL
statements after the update. Yes, it works (although presumably it
wouldn't if the user got to the second button before the update
completed) but there must be a better way.
Apr 7 '08 #4
Boris,

What is the purpose of this code below?
I have never seen it.

Finally
strSQL = "INSERT INTO tbl1 (a, b, c) SELECT etc ....... ;"
db.DoCmd.RunSQL(strSQL)
MessageBox.Show("Save completed")
End Try
Cor
Apr 7 '08 #5
On 7 Apr, 17:25, "Cor Ligthert[MVP]" <notmyfirstn...@planet.nlwrote:
Boris,

What is the purpose of this code below?
I have never seen it.

Finally
* * * * strSQL = "INSERT INTO tbl1 (a, b, c) SELECT etc ....... ;"
* * * * db.DoCmd.RunSQL(strSQL)
* * * * MessageBox.Show("Save completed")
End Try

Cor
Sorry, I was trying to simplify the code and I've made it harder to
understand.

What that block represents is a series of updates to other tables in
the same database based on the new data that has just been put into or
amended through the table adapter.

The reason I did this was because the table adapter update works and
all the rest of the code works but only if I stop the process after
the tableadapter.update line and then run the remaining code
seperately. If they follow up in sequence the queries do NOT include
the updated data, although when you look at the database after the
procedure has run this core table in the database (the one updated by
the tableadapter) is correct
Apr 7 '08 #6
Boris227 wrote:
>Try
Me.DiagAddTableAdapter.Update(Me.Visir_RTDS_v3Dat aSet3)
Catch
MessageBox.Show("An error occurred during the update
process")
Finally
strSQL = "INSERT INTO tbl1 (a, b, c) SELECT etc ....... ;"
db.DoCmd.RunSQL(strSQL)
MessageBox.Show("Save completed")
End Try- Hide quoted text -

- Show quoted text -

My current work around is to provide a second button for all the SQL
statements after the update. Yes, it works (although presumably it
wouldn't if the user got to the second button before the update
completed) but there must be a better way.
I read your reply to Cor, but I answered here because you have the code here.

I think you are encountering a problem of using two different connections. The
line db.DoCmd.RunSQL(strSQL) is probably not using the same connection to the
database that Me.DiagAddTableAdapter.Update(Me.Visir_RTDS_v3Data Set3) is using.

The database won't fully commit the changes instantaneously, so the second
connection may or may not seem them, depending on how soon after the update it
runs. Sound familiar?

You might be able to fix it by using a transaction around the first update, and
committing it, but the better solution is to use the same connection for both
updates. That might take a little rearranging, but if you do a sequence like
Open connection
Run first update
Run second update
Close connection
you should get the data consistency you are looking for.
Apr 8 '08 #7
Boris,

So is that is processed, then the Update is as well processed, or even more,
if the update is not processed, then the finally will be processed.

In my idea not clever to set this code in a finally block. A finally block
is forever processed as long as you don't power down the computer.

In your place I would start to seperate the processes, while my first
opinion is that your problem is in your second situation, not in the
standard update.

Cor

"Boris227" <ad***********@btinternet.comschreef in bericht
news:52**********************************@s39g2000 prd.googlegroups.com...
On 7 Apr, 17:25, "Cor Ligthert[MVP]" <notmyfirstn...@planet.nlwrote:
Boris,

What is the purpose of this code below?
I have never seen it.

Finally
strSQL = "INSERT INTO tbl1 (a, b, c) SELECT etc ....... ;"
db.DoCmd.RunSQL(strSQL)
MessageBox.Show("Save completed")
End Try

Cor
Sorry, I was trying to simplify the code and I've made it harder to
understand.

What that block represents is a series of updates to other tables in
the same database based on the new data that has just been put into or
amended through the table adapter.

The reason I did this was because the table adapter update works and
all the rest of the code works but only if I stop the process after
the tableadapter.update line and then run the remaining code
seperately. If they follow up in sequence the queries do NOT include
the updated data, although when you look at the database after the
procedure has run this core table in the database (the one updated by
the tableadapter) is correct

Apr 8 '08 #8
On 8 Apr, 03:31, "Steve Gerrard" <mynameh...@comcast.netwrote:
Boris227 wrote:
Try
Me.DiagAddTableAdapter.Update(Me.Visir_RTDS_v3Data Set3)
Catch
MessageBox.Show("An error occurred during the update
process")
Finally
strSQL = "INSERT INTO tbl1 (a, b, c) SELECT etc ....... ;"
db.DoCmd.RunSQL(strSQL)
MessageBox.Show("Save completed")
End Try- Hide quoted text -
- Show quoted text -
My current work around is to provide a second button for all the SQL
statements after the update. Yes, it works (although presumably it
wouldn't if the user got to the second button before the update
completed) but there must be a better way.

I read your reply to Cor, but I answered here because you have the code here.

I think you are encountering a problem of using two different connections.The
line db.DoCmd.RunSQL(strSQL) is probably not using the same connection to the
database that Me.DiagAddTableAdapter.Update(Me.Visir_RTDS_v3Data Set3) is using.

The database won't fully commit the changes instantaneously, so the second
connection may or may not seem them, depending on how soon after the update it
runs. Sound familiar?

You might be able to fix it by using a transaction around the first update, and
committing it, but the better solution is to use the same connection for both
updates. That might take a little rearranging, but if you do a sequence like
* * * * Open connection
* * * * Run first update
* * * * Run second update
* * * * Close connection
you should get the data consistency you are looking for.- Hide quoted text-

- Show quoted text -
Yes, they are definitely using different connections because I just
created a new one through the DataGridView wizard. I never thought of
that. It sounds promising. I will give this a go.
Apr 8 '08 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Jozef | last post by:
Hello, I'm trying to check for and add a field to a table to a back end database through code. The problem I've been faced with is changing permissions, because I have to use administer...
1
by: RobZ via DotNetMonster.com | last post by:
Hi all, I am using a tableadapter to read data from a table - no problem, I have configured the Tableadapter to add an InsertQuery. My problem is when I first Call the InsertQuery and then...
0
by: vbnetguy | last post by:
Hopefully someone has an answer for this or maybe I am missing something. I have a stored procedure - this stored procedure is used as my main insert for a tableadapter I am doing something...
1
by: Magnus | last post by:
My situation compares to this: I have two tables parentTable(id, foreignId) and childTable(id, value). "foreignId" in the "parentTable" references "id" in "childTable". The constraint is by default...
1
by: dee | last post by:
I have a table 'LeadHistory' which has among others, the following fields. Salesman(Text) SalesmanAssmntDate(Date/Time) Disposition(Text) I also have a table 'LookUpSalesman' which has among...
5
by: dani kotlar | last post by:
I run the following code: this.carsBindingSource.EndEdit(); this.carsTableAdapter.Update( this.vehiclesDataSet.Cars ); in order to save changes in the dataset to the database, but the changes...
4
by: Nikolay Unguzov | last post by:
Hi, I want to know how to start two or more async methods, but wait each one to complete, before proceed to the next one. My goal is to do many time-consuming tasks one after other but not block...
0
by: arevans | last post by:
I can't seem to update the data source when I call the tableadapter's update method. Here is my code: DealsTableAdapter ta = new DealsTableAdapter(); dsDeals.DealsDataTable dt = new...
0
jas16183
by: jas16183 | last post by:
Hi Guys, need some help here, Im working on a project in vb.net, the problem im facing is that my tableadapter.update(dataset.datatable) is not functioning, the datatable has a relation with...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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,...

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.