Solved

Executing the query

Posted on 2006-11-27
3
265 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
[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
3 Comments
 
LVL 30

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

Industry Leaders: 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!

Question has a verified solution.

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

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

710 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