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.
Now the control returns to the form and I call
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.
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()Code:
myDataTable.Clear()
dataAdapter.Fill(myDataTable)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.