Results 1 to 4 of 4

Thread: [RESOLVED] Thread issue? DataGridView does not update immediately

Threaded View

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Apr 2013
    Posts
    134

    Resolved [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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width