我用的是stringgrid连接数据库!关于提高性能的问题

我用的是stringgrid连接数据库!关于提高性能的问题 Delphi / Windows SDK/API
http://www.delphi2007.net/DelphiDB/html/delphi_20061219110009225.html
我有上万条的记录由于实际需要需要用到stringgrid控件!然而每次往里面添加纪录的时候都非常慢!  
  例如:  
  StringGrid1.Cells[1,i]:=ADOQuery1.FieldByName('aa').AsString;  
  。  
  。。。  
  有什么更好的其他办法可以提升速度呢?请高人指点!

分页来做吧~~~  
   
  否则真的太辛苦了

让记录在StringGrid中分页显示在Uses中加入:   ADOInt    
     
  //首先设定PageSize,取出PageCount  
  procedure   TForm1.Button1Click(Sender:   TObject);  
  begin  
      ADoquery1.Recordset.PageSize   :=spinedit1.Value;  
      Edit1.Text   :=   IntToStr(ADoquery1.Recordset.PageCount);  
      ShowData(spinedit2.Value);  
  end;    
     
  //然后将AbsolutePage的数据乾坤大挪移到StringGrid1中    
  procedure   TForm1.ShowData(page:integer);  
  var  
      iRow,   iCol,   iCount   :   Integer;  
      rs   :   ADOInt.Recordset;  
  begin  
      ADoquery1.Recordset.AbsolutePage:=Page;  
      Currpage:=page;      
      iRow   :=   0;  
      iCol   :=   1;  
      stringgrid1.Cells[iCol,   iRow]   :=   'FixedCol1';  
      Inc(iCol);  
      stringgrid1.Cells[iCol,   iRow]   :=   'FixedCol2';  
      Inc(iRow);  
      Dec(iCol);  
      rs   :=   adoquery1.Recordset;  
      for   iCount   :=   1   to   SpinEdit1.Value   do    
      begin  
          stringgrid1.Cells[iCol,   iRow]   :=   rs.Fields.Get_Item('FieldName1').Value;  
          Inc(iCol);  
          stringgrid1.Cells[iCol,   iRow]   :=   rs.Fields.Get_Item('FieldName1').Value;  
          Inc(iRow);  
          Dec(iCol);  
          rs.MoveNext;  
      end;  
         
  //上一页    
  procedure   TForm1.Button2Click(Sender:   TObject);  
  begin  
      If   (CurrPage)<>1   then  
          ShowData(CurrPage-1);  
  end;  
     
  //下一页  
  procedure   TForm1.Button3Click(Sender:   TObject);  
  begin  
      If   CurrPage<>ADoquery1.Recordset.PageCount   then  
          ShowData(CurrPage+1);  
  end;

转载于:https://www.cnblogs.com/delphi2007/archive/2009/02/19/1394126.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值