Solved

Executing the query

Posted on 2006-11-27
3
229 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 29

Accepted Solution

by:
anarki_jimbel earned 500 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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

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…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This video discusses moving either the default database or any database to a new volume.

758 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

19 Experts available now in Live!

Get 1:1 Help Now