Solved

wait for completion ExecuteNonQuery command

Posted on 2004-08-03
8
1,943 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
Independent Software Vendors: 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 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
ASP.NET - Why is accordion not working? 3 65
Windows Universal App 22 52
.NET Redemption/Outlook Examples 3 24
Read top line from CSV file 14 55
Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

739 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