c# - Need to when ExecuteNonQuery has finished before proceeding to next line of code -


I searched and checked, but I do not know what I want. To update the local Ace database, I am using ExecutionCalize of a data adapter update command. When I run the code, ExecuteNonQuery does not end before the next line of code is executed and therefore, the update grid is not reflected in my grid or my text box. If I put a message box after ExecuteNonQuery, then when I hit OK in the message box, the rest of the code is executed and the updated database appears in my grid and text box. Or if I step into the debug for code execution without the message box, the update of the database is reflected on my form. But if I slow down or shut down the query without having to run the code, the update is not shown in my control.

  OleDbConnection connection = New OleDbConnection (connString); String sql = "update table 1 set country = '" + txtNewText.Text + "' SomeNum = 1111 '; connection.Open (); DAdapter.UpdateCommand = connection.CreateCommand (); DAdapter.UpdateCommand.CommandText = sql; dAdapter UpdateCommand.ExecuteNonQuery (); //MessageBox.Show("Pause "); dTable.Clear (); // Clear or add everything that was there. DAdapter.Fill (dTable); line = decimal.ro [0]; TxtCompany.Text = Row ["name"]. ToString (); TxtGenre.Text = Line ["Job"]. ToString (); TxtId.Text = Line ["ID"]. ToString (); TxtSomeNum .Text = Line ["Some Numbers"]. ToString (); TxtCountry.Text = Line ["Country"]. ToString ();  

I agree that the data table The update query is not finished before filling again. Anyone can help me with this. I looked at something to show the status of the update query, but I did not know what I needed. / P>

VH


10/28/14 Last night I added dAdapter.UpdateCommand.ExecuteNonQuery () right after dAdapter.UpdateCommand.ExecuteNonQuery (); So everything worked out. I was not sure that this was just something that took enough time to allow the query to end and therefore to show updates, or if it was just some of the "band-associates" that worked, then I Replaced with connection Close (); And he also worked. Again ... I do not know if I ended the connection after ending the query and before turning on the connection to the next line of code, or because I had other people "Fifing" to do this work I have seen similar problems in finding the answer but I have not understood anyone what the problem is and why this happens or the most appropriate solution.

You should use OleDbDataReader , because you SQL < / Em> are not used.

An example:

  (using OLDB connection connection = new OLDB connection (connection string)) {OleDbCommand command = new OleDbCommand (queryString, Connection); Connection.Open (); OleDbDataReader Reader = command.ExecuteReader (); While (reader.Read ()) {Console.WriteLine (Reader [0]. Ostring ()); } Reader. Stop it (); }  

It will be again through every specified column so that you will have to fill in your data. Documentation can be found.


Comments