Recent

Author Topic: Dbgrid row count  (Read 1804 times)

mpknap

  • Full Member
  • ***
  • Posts: 116
Dbgrid row count
« on: January 31, 2020, 09:50:41 am »
I can't find on the internet how to count how many rows have dbgrid1 (or sql records loaded into dbgrid)?
later there will be information in label1.caption

lucamar

  • Hero Member
  • *****
  • Posts: 2824
Re: Dbgrid row count
« Reply #1 on: January 31, 2020, 11:07:16 am »
Try with DBGrid.DataSource.DataSet.RecordCount, but, as the docs say, remember that:

Quote
RecordCount is the number of records in the dataset. This number is not necessarily equal to the number of records returned by a query. For optimization purposes, a TDataset descendent may choose not to fetch all records from the database when the dataset is opened. If this is the case, then the RecordCount will only reflect the number of records that have actually been fetched at the current time, and therefor the value will change as more records are fetched from the database.

Only when Last has been called (and the dataset has been forced to fetch all records returned by the database), will the value of RecordCount be equal to the number of records returned by the query.
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus 2.0.6/FPC 3.0.4 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

mpknap

  • Full Member
  • ***
  • Posts: 116
Re: Dbgrid row count
« Reply #2 on: February 01, 2020, 09:33:47 am »
yes
label1.Caption:=DataSource1.DataSet.RecordCount.ToString;

displays the number of records on the screen in dbgrid.
Just using DBNavigator click manualy on "Last" button
and then in label1 it will show how many are all.

And how to programatically press "Last" button in DBNavigator?


HeavyUser

  • Sr. Member
  • ****
  • Posts: 308
Re: Dbgrid row count
« Reply #3 on: February 01, 2020, 10:48:25 am »
yes
label1.Caption:=DataSource1.DataSet.RecordCount.ToString;

displays the number of records on the screen in dbgrid.
Just using DBNavigator click manualy on "Last" button
and then in label1 it will show how many are all.

And how to programatically press "Last" button in DBNavigator?
Code: Pascal  [Select][+][-]
  1. DataSource1.DataSet.Last;
  2.  

mpknap

  • Full Member
  • ***
  • Posts: 116
Re: Dbgrid row count
« Reply #4 on: February 01, 2020, 06:03:25 pm »
Code: Pascal  [Select][+][-]
  1.   datasource1.DataSet.Last;
  2.     datasource1.DataSet.First;
  3.     label11.Caption := 'Rec ' + DataSource1.DataSet.RecNo.ToString + '  of ' +
  4.       DataSource1.DataSet.RecordCount.ToString;
  5.      

thx :)

 

TinyPortal © 2005-2018