zoukankan      html  css  js  c++  java
  • 提高AdoQuery的速度

     用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;
  • 相关阅读:
    jackson自动将东八区时间转成标准时间
    开发项目和所用时间 感想
    自我介绍
    后缀数组模板
    lucas模板
    后缀数组da3模板
    cf#366....
    第1月2周1天
    第1月2周2天
    第1月1周1天
  • 原文地址:https://www.cnblogs.com/m0488/p/3800523.html
Copyright © 2011-2022 走看看