SOS:连接Paradox数据库的 dm1.query2.RecordCount+1 语句在连接SQL Server中应如何改? (100分)

C

cqjoe

Unregistered / Unconfirmed
GUEST, unregistred user!
请教:连接Paradox数据库时 for i:=2 to dm1.query2.RecordCount+1 do 语句 可以正确执行,但连接SQL Server不能正确执行,dm1.query2.RecordCount+1应如何改?

例子:
workbook:=eclapp.workbooks.open(xlsfilename);
for i:=2 to dm1.query2.RecordCount+1 do { Paradox数据库可以执行,但SQL Server不行,dm1.query2.RecordCount+1应如何改?}
begin
eclapp.cells(i,1):=dm1.query2.FieldByName('dwname').asstring;
workbook.save;
dm1.query2.Next;
end;
workbook.save;
 
这个语句没有问题。
我在WIN2K,SQL2000运行都没问题。下面是我的代码:procedure TForm1.Button1Click(Sender: TObject);
var
i,j:integer;
begin
j := 0;
with adoquery1 do
begin
open;
showmessage(inttostr(recordcount));
for i := 2 to recordcount+1 do
begin
j := j+1;
next;
end;
prior;//用SQL2000需要此句。其他则可不用。
end;
showmessage(inttostr(j));
end;
end.
 
多谢xynet。
此方法ADO可行,但BDE不行。
 
为什么不用for i:=1 to dm1.query2.RecordCount do呢?可以解决。
 
query.RecordCount这个东西有bug,经常取不出数据,如果要使用,
在query.open后执行query.last,然后再query.first,最后再用query.RecordCount,
你试一下。
另外,最好将query.RecordCount付给一个变量,在执行for循环时使用变量
而不用query.RecordCount,可以加快速度。
 
recordcount并不能总返回正确的记录数量,在sqlserver等网络数据库中经常会为-1
用select count(*) from... where..

query1.first;
while not query1.eof do
begin
..
query1.next;
end;
 
接受答案了.
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
I
回复
0
查看
742
import
I
I
回复
0
查看
744
import
I
顶部