Solved

Stop ADO query in the middle of execution in VB6

Posted on 2004-08-04
6
517 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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…

777 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