Solved

wait for completion ExecuteNonQuery command

Posted on 2004-08-03
8
1,899 Views
Last Modified: 2006-11-17
How can I force my program to wait for completion ExecuteNonQuery command on Access database?

Thanks

Morfo
0
Comment
Question by:morfo
8 Comments
 
LVL 9

Expert Comment

by:s_sansanwal
ID: 11711255
Could you update more?
I think program by default runs a statement at one time and hence would wait when calling excutenonquery before moving to next line
0
 

Author Comment

by:morfo
ID: 11712757
I have small C# application. I use OleDbConnection to access to mdb database file.

I have listbox on my form where is shown for example list of companies. To insert new company I call (ShowDialog()) new form, where user fill all necessary informations. After click on accept button I call insert command:

myCommand.CommandText = "INSERT INTO companies (xxxx) VALUES (yyyy)";
try
{
      myCommand.ExecuteNonQuery();
}
catch (System.Data.OleDb.OleDbException ex)
{
      MessageBox.Show(ex.Message);
}
this.close();

On end of insert procedure I close dialog form and on main form I call refresh procedure, where I clear my listbox, I access to database and I read new listbox items. And new company is not shown between comapanies items. I need refresh form again.

When after
      myCommand.ExecuteNonQuery();
line I insert line
      MessageBox.Show("Wait a moment!");
and before click OK I wait a few seconds, new company is represented between listbox items. But this is not very cool solution. I want to force my application programatically to wait for executing insert command. How do it?

0
 
LVL 7

Expert Comment

by:Ceiled
ID: 11712889
That's very odd...when I do something similar, it seems to be running synchronously, and I haven't been able to see the old values, even though I look at it immediately after updating it. You might try running the command in a transaction -- call BeginTransaction() on the connection, set the Transaction property of the command that you're executing, then call Commit() on the transaction. If that doesn't help, then I'm not sure where to go from there. Perhaps you somehow toggled a setting that puts the data system into asynchronous mode?
0
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 

Author Comment

by:morfo
ID: 11741994
It doesn't works too.
I first time meet with this problem. Usually I work with SQL Server and there I haven't similar problems .
Possilble is everything, but how can I set it? I have no ideas.
0
 
LVL 7

Accepted Solution

by:
psdavis earned 50 total points
ID: 11754778
I've used this approach a lot with Ado.Net and Access database.  The ExecuteNonQuery is definitely running Synchronously.  That's not your error.

I'm betting you have a totally different error than what you are expecting.

Put another catch in.  I know of a bug where if you are running this in response to an event or in a different thread, the Exception is ingored.

try
{
     myCommand.ExecuteNonQuery();
}
catch (System.Data.OleDb.OleDbException ex)
{
     MessageBox.Show(ex.Message);
}
catch( Exception ex )
{
   MessageBox.Show( ex.Message );
}
0
 

Author Comment

by:morfo
ID: 11760031
I try it and no exception appears. I have some other parts of code in try statement after ExecuteNonQuery command. And this code allways runs correctly. All my application runs in one thread. I think that the only one explanation for my problem is that myCommand running asynchronously.

Morfo
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question