用TDataSet及其派生类如TAdoQuery对数据库进行查找时,

如果TDataSet类 没有与数据感知控件相连,通过调用DisableControls可以极大地提高查询速度

特别是在数据比较多的情况下。

下面一段代码查询一个45000条记录的表,

不调用DisableControls时需要 执行30到40秒,

调用DisableControls后只需要1秒到2秒。

 

procedure TForm1.Button2Click(Sender: TObject);
var Time : DWORD;
begin
  Time := GetTickCount;
  AdoQuery1.Close;
  AdoQuery1.SQL.Clear;
  AdoQuery1.SQL.Add('select * from table');
  AdoQuery1.DisableControls;
  AdoQuery1.CacheSize := 1000; // 影响不是很大
  AdoQuery1.Open;
  while not AdoQuery1.Eof do
  begin
    AdoQuery1.Next;
  end;
  AdoQuery1.EnableControls; // 恢复,与DisableControls配对调用。
  Time := GetTickCount - Time;
  Label1.Caption := IntToStr(Time);
end;

 

 

 

相关文章:

  • 2021-06-19
  • 2022-02-23
  • 2021-06-07
  • 2021-06-12
  • 2022-12-23
  • 2021-08-12
  • 2021-05-16
  • 2021-09-15
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-06-27
  • 2021-09-27
相关资源
相似解决方案