Is there any faster way to iterate through an ADO Dataset than
while (not ADOQuery1.Eof) do
begin
/* Do something */
ADOQuery1.Next;
end;
I need to scan a dataset of around 9000 items and only extract records matching a pre-defined set of branch numbers.
ADO, (Microsoft ActiveX Data Objects) is a set of COM objects that access data through an OLE DB provider. The dbGo components encapsulate these ADO objects in the Delphi database architecture.
Be sure that you use DisableControls/EnableControls if it's not necesary for not spend time updating visible controls associated at DataSet.
try
ADOQuery1.DisableControls;
while (not ADOQuery1.Eof) do
begin
/* Do something */
ADOQuery1.Next;
end;
finally
ADOQuery1.EnableControls;
end;
Regards.
@Pieter, two options
1) you can modify your sql sentence before to execute, adding the where condition wich match with the pre-defined set of branch numbers.
2) using the Filter property of TAdoQuery.
AdoQuery1.close;
AdoQuery1.filter := 'your condition goes here';
AdoQuery1.filtered := true;
AdoQuery1.Open;
It is much faster to use ADORecordset for such tasks:
while not ADOQuery1.Recordset.EOF do
begin
ADOQuery1.Recordset.MoveNext;
// get value
SomeVar := ADOQuery1.Recordset.Fields['FieldName'].Value;
end;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With