Solved

wait for completion ExecuteNonQuery command

Posted on 2004-08-03
8
1,872 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
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
The Using statement in C# 5 37
Using Simpleject with Class Library 11 25
Image(2) 3 29
COnsume rest client 6 16
Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
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…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

744 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now