关于IBQuery1.RecordCount永远等于1的问题?(急急急)(200分)

  • 主题发起人 主题发起人 kjgen
  • 开始时间 开始时间
K

kjgen

Unregistered / Unconfirmed
GUEST, unregistred user!
用D5+INTERBASE开发,用IBTABLE及IBQUERY联接数据,
问题是我想计算一TABLE中所有记录的数量,使用到
IBQuery1.RecordCount取值,但IBQuery1.RecordCount永远等于1
请指教。
另:用D5的IB控件是不是可不用BDE或ODBE联接数据。
 
是不是先在query.sql里select ...where..and ...
限制到最后,query里只有一条记录了?(瞎猜)
 
用SQL语句:
select count(*) from table where ......
再得到其返回值。
可能更好些,RecordCount问题不少。
 
你先last,再first试试。
 
http://www.gislab.ecnu.edu.cn/delphibbs/DispQ.asp?LID=157301
http://www.gislab.ecnu.edu.cn/delphibbs/DispQ.asp?LID=150943
 
IBQuery1.Active := false;
IBQuery1.Active := TRUE;
 
1、last/first方法简单,但速度慢,在某些场合也可能得不到正确结果;
2、select count(*) from table...速度比较快;
3、stored proc方法:select count(*) from ... into :result...
此法使用复杂,但速度和可靠性均比较好。

chenlili君的方法并不能解决该问题。
 
TIBQuery.RecordCount does the same thing as TIBSQL.RecordCount. Here
is what Help says for TIBSQL.RecordCount:

Use the RecordCount property to see how many records are returned by
a query. If the result set is to return 100 rows, RecordCount will
only be 100 after all the records have been visited. That is, after
looking at the first record, RecordCount is 1, and so forth.

The reason RecordCount operates in this fashion is calculating all
the records in a dataset is potentially time consuming operation as
it would require scanning through the entire dataset. <FONT> COLOR="RED">The most
efficient way to calculate the number of records in a dataset is to
execute a SELECT COUNT(*) statement. </FONT>

 
1 确保QUERY。ACTIVE=TRUE
2 QUERY中的SQL返回的DATASET NOT NULL
3 取RECONDCOUNT 前先LAST
 
接受答案了.
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
1K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
900
SUNSTONE的Delphi笔记
S
后退
顶部