?
Solved

wait for completion ExecuteNonQuery command

Posted on 2004-08-03
8
Medium Priority
?
1,988 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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 150 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

762 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