Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6020297
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T03:32:51+00:00 2026-05-23T03:32:51+00:00

I am using SDAC components to query a SQL Server 2008 database. It has

  • 0

I am using SDAC components to query a SQL Server 2008 database. It has a recordcountproperty as all datasets do and it also has the FetchAll property (which I think it is called packedrecords on clientdatasets). Said that, I got a few questions:

1 – If I set FetchAll = True the recordcount property returns ok. But in this case, when I have a large database and my query returns a lot of lines, sometimes the memory grows a lot (because it is fetching all data to get the recordcount of course).

2 – If I set FetchAll = False, the recordcount returns -1 and the memory does not grow. But I really need the recordcount. And I also wanna create a generic function for this, so I dont have to change all my existent queries.

What can I do to have the recordcount working and the memory usage of the application low in this case?

Please, do not post that I dont need recordcount (or that I should use EOF and BOF) because I really do and this is not the question.

I thought about using a query to determine the recordcount, but it has some problems since my query is going to be executed twice (1 for recordcount, 1 for data)

EDIT

@Johan pointed out a good solution, and it seems to work. Can anybody confirm this? I am using 1 TMSCconnection for every TMSQuery (because i am using threads), so I dont think this will be a problem, will it?

  MSQuery1.FetchAll := False;
  MSQuery1.FetchRows := 10;
  MSQuery1.SQL.Text := 'select * from cidade';
  MSQuery1.Open;
  ShowMessage(IntToStr(MSQuery1.RecordCount)); //returns 10
  MSQuery1.Close;

  MSQuery2.SQL.Text := 'SELECT @@rowcount AS num_of_rows';
  MSQuery2.Open;
  ShowMessage(MSQuery2.FieldByName('num_of_rows').AsString); //returns 289

EDIT 2*

MSQuery1 must be closed, or MSQuery2 will not return the num_of_rows. Why is that?

  MSQuery1.FetchAll := False;
  MSQuery1.FetchRows := 10;
  MSQuery1.SQL.Text := 'select * from cidade';
  MSQuery1.Open;
  ShowMessage(IntToStr(MSQuery1.RecordCount)); //returns 10
  //MSQuery1.Close; <<commented

  MSQuery2.SQL.Text := 'SELECT @@rowcount AS num_of_rows';
  MSQuery2.Open;
  ShowMessage(MSQuery2.FieldByName('num_of_rows').AsString); //returns 0
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T03:32:52+00:00Added an answer on May 23, 2026 at 3:32 am

    Run your query as normal, than close the query

    MSQuery1.SQL.Text := 'select * from cidade';     
    MSQuery1.Open;     
    MSQuery1.Close;  
    

    You need the close otherwise SQL-server has not closed the cursor yet, and will not register the query as ‘completed’.

    and run the following query right afterwards:

    SELECT @@rowcount AS num_of_rows
    

    This will select the total number of rows your last select read.
    It will also select the number of rows your update/delete/insert statement affected.

    See: http://technet.microsoft.com/en-us/library/ms187316.aspx

    Note that this variable is per connection, so queries in other connections do not affect you.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using SQL Server 2005 Leave Table ID StartDate EndDate 001 02/03/2010 02/03/2010 002 02/03/2010
Using C#, I need a class called User that has a username, password, active
Has anyone got EclipseLink MOXy (I'm using eclipselink 2.1.0) to work with Java 5?
Using Java, how can I extract all the links from a given web page?
Using Spring MVC, do interceptors only intercept defined controller mappings or can they also
using CodeIgniter normally one has to specify the controllers in the config/routes.php file. This
using Core Data, how would I list (i.e. return an NSArray of NSStrings) all
Using online interfaces to a version control system is a nice way to have
Using PyObjC , you can use Python to write Cocoa applications for OS X.
Using ASP.NET MVC there are situations (such as form submission) that may require a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.