Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Executing the query

Posted on 2006-11-27
3
Medium Priority
?
279 Views
Last Modified: 2010-04-16
Hi,

I am making Windows Application in C# with SQL 2005

On my click button I am executing a query, Queru has multiple records.

It is like

SqlDataReader objRdr

while (objRdr.Read())
{
}

Now, I have another stop button, now as soon as someone clicks on the stop button from windows application form,

my while loop do not work anymore and everything should stop, I can call my terminate process.

Can anyone help me how to do this

Many thanks in advance
0
Comment
Question by:dinesh_bali
3 Comments
 
LVL 30

Accepted Solution

by:
anarki_jimbel earned 2000 total points
ID: 18022709
You want to stop reading you results from the query? But how long does it take to read data? Is it so big?

One possible solution to add another (global) boolean value that you set with your stop button, e.g. bool stop.
Initially it is false, when stop button clicked it becomes true.
I your loop you check:


while (objRdr.Read() && !stop)
{
}
0
 
LVL 7

Expert Comment

by:Mohamed Zedan
ID: 18022881
also add this line inside the loop if you want to form to be responsive and the user able to click the stop button
unless you are running the loop in another thread other than the main application thread.

while (objRdr.Read() && !stop)
{
    //Do your work
    System.Windows.Forms.Application.DoEvents();
}
0
 
LVL 5

Expert Comment

by:rameedev
ID: 18025558
If your process of executing the query is very cpu intensive then i suggest you invoke this on a separate thread..this way you have 2 ways of stopping the process

a) Kill your sub thread  by calling abort() or join()
b) as anarki_jimbel said update a string variable value and you can check it each time as mohzedan said
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
High user turnover can cause old/redundant user data to consume valuable space. UserResourceCleanup was developed to address this by automatically deleting user folders when the user account is deleted.
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Screencast - Getting to Know the Pipeline
Suggested Courses

926 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