Solved

Stop ADO query in the middle of execution in VB6

Posted on 2004-08-04
6
519 Views
Last Modified: 2013-12-25
Hi all

I am trying to do a query which returned around 10.000 rows and put it in the MSHFlexGrid.
Command is like

strsql = "select * from [table_name]"
rs.open strsql,[connection_name]

set mshflexgrid.datasource = rs

I would like to stop the query in the middle of execution and put the happen being executed rows in the mshflexgrid. (like in SQL Query analyzer)

Is that possible ?

Please advise.
0
Comment
Question by:joris_navius
  • 2
6 Comments
 
LVL 53

Accepted Solution

by:
Dhaest earned 125 total points
ID: 11723602
I guess it's not possible. But my question for you is: why get so many rows in your flexgrid ? It will take a lot of memory and time to get all those records.
0
 

Author Comment

by:joris_navius
ID: 11723931
Hi Dhaest

I am creating small tool as an add-in in my applications (like Query Analyzer) so user can create their own query. Just in case the user select lot of rows and want to stop it, do you have any advise about this ?

thanks
0
 
LVL 19

Expert Comment

by:Rimvis
ID: 11726204
You cannot expect that you will stop a query execution in the middle and it will return a half of results. Sure, for simple queries like "SELECT * FROM SomeTable" this might work, but in general, it depends on what execution plan SQL Server will use. Specially in complex queries with multiple JOINs and sub-selects.

I suggest you must limit amount of rows BEFORE the quety execution. So if user will try to execute query "SELECT Something FROM SOmeTable" with result limit of 10000 rows, you will have to do this:

sQuery = "SELECT TOP " & iResultLimit & Mid$(sQuery, 7) ' replace SELECT with SELECT TOP x
0
 
LVL 19

Expert Comment

by:Rimvis
ID: 11726298
Or better, use MaxRecords property of Recordset object:

Private Sub Form_Load()
    Dim con As New ADODB.Connection
    Dim rst As New ADODB.Recordset
   
    con.Open "<your connection string>"
   
    rst.MaxRecords = 10000 'YOUR RECORD LIMIT
   
    rst.Open"SELECT Something FROM SOmeTable", con
   
    Do While Not rst.EOF
       ' add rows to grid

        rst.MoveNext
    Loop
   
    rst.Close        
    con.Close
   
End Sub
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone 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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

839 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