Learn how to a build a cloud-first strategyRegister Now



Posted on 2006-05-18
Medium Priority
Last Modified: 2010-04-23
I have a form with a datagrid and  a search button.

This search could retrieve from 1 to 100 million records.

I would like to able to cancel the search process either by having:

1- cancel button on the same form: which will cancel the database retrieval
2- by opening a new form with a progressbar  and a cancel button:
when you press the cancel button will send a database a cancel retrieval

Thanks for your help
Question by:elianexex
1 Comment
LVL 34

Accepted Solution

Sancler earned 1000 total points
ID: 16713848
You will need to use either a DataReader (which I would probably go for) or a DataAdapter with its .Fill arguments including StartRecord and MaxRecords - see this


If you declare (within a scope available to your data reading procedure)

    Dim CancelRead As Boolean = False

you could, whether on the same form or another form, set it to True if the user pressed the Cancel button.

You can then interrupt the DataReader's reading process with

   While MyDataReader.Read
      'your code to use the datarow read
      If CancelRead Then Exit While
   End While

or, with a DataAdapter, something like

   Dim firstRecord As Integer = 0
   Dim batchSize As Integer = 1000
   Dim returned As Integer
      returned = MyDataAdapter.Fill(MyDataSet, firstRecord, batchSize, MyTable)
      If returned < batchsize Then Exit Do
      If CancelRead Then Exit Do
      firstRecord += batchsize

I've not tested this code, by the way.  Its principles are OK, but I'm not guaranteeing the syntax or my typing.


Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses
Course of the Month20 days, 19 hours left to enroll

810 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