|
-
May 24th, 2013, 03:25 AM
#1
Thread Starter
Addicted Member
[RESOLVED] Thread issue? DataGridView does not update immediately
Hi!
I have a form with a DGV bound to a DataTable throught a bindingsource. The dataTable gets filled by a DataAdapter.
Now the form loads, everything is fine. Then the user presses a button, to create a new record, and a form opens where the user can input all data for the new record. When the user saves the new record, I call an Insert statement on the database.
Code:
Private Sub cmdOK_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdOK.Click
.... checking all values, then calling insert ....
mySQL.Connection = transactionConnection
mySQL.Transaction = trans
mySQL.CommandText = "insert into doc... "
mySQL.ExecuteNonQuery()
.... based on some conditions some other INSERT and UPDATE statements are called, those need to be in a transaction
trans.Commit()
transactionConnection.Close()
Now the control returns to the form and I call
Code:
myDataTable.Clear()
dataAdapter.Fill(myDataTable)
So that the newly inserted record gets fetched from the database.
BUT, this does not work, the new record does not get fetched from the database. If, however, after returning to the base form I wait a few seconds before refilling the table (I simply opened a MsgBox and didn't close for a few seconds, then the Fill method gets also the new record.
So I wonder if the control returns from the "subform" although the database queries are not yet fully executed. How can I guarantee, that when I call transaction.commit, that the next line of code is called only after the transaction in the database has been finished.
Last edited by AndyLD; May 24th, 2013 at 04:16 AM.
-
May 24th, 2013, 04:20 AM
#2
Thread Starter
Addicted Member
Re: Thread issue? DataGridView does not update immediately
Oh, now I understood the problem source. The INSERT command and the commands in the transaction use a separate DB connection. So things run in parallel here, I will look for a solution to this.
Last edited by AndyLD; May 24th, 2013 at 04:29 AM.
-
May 24th, 2013, 07:17 AM
#3
Re: Thread issue? DataGridView does not update immediately
Don't insert directly into the database... add the record to the datatable, then call the update method to push the changes back to the database...
-tg
-
May 25th, 2013, 06:26 AM
#4
Thread Starter
Addicted Member
Re: Thread issue? DataGridView does not update immediately
I insert the data manually directly into the database, because the application is used in locations with poor electric power stability, and many of the clients don't have UPS units installed, so I want to get the data to the database as fast as possible. Also, the data I am talking in this thread is data, that comes directly from a form with many input fields, not a GridView, so in this form I don't have an underlying DataTable, however part of this data is shown in the form to which the user returns after inserting the data.
Probably I have a nasty solution, but after I return to the first form, I let the user wait while the new record is fetched from the database. Meanwhile the user gets a message to wait for a moment.
On my machine this waiting time is approx 0.5 seconds, so I let the message visible for at least one second, so the user does not get confused if a message appears and disappears too fast.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|