我再dbgrid的 onDrawColumnCell事件中编写代码,为什么我用adoQuery 就能获取到RecNo 但是通过TQuery 获取到的为什么总是 -1 呢?

解决方案 »

  1.   

    你的數據集TQUERY沒有打開,或者沒有任何數據.
      

  2.   

    你把
    adoquery.cursorlocation := clUseClient;
    adoquery.cursortype := ctKeyset;
    adoquery.locktype := ltOptimistic;试试
      

  3.   

    这可能就是adoQuery 和TQuery的区别....
      

  4.   

    对于oracle,sqlserver这类数据库,TQuery不能得到确的RecNo 
    而我建议的方法是,在数据表设计中加一唯一ID
      

  5.   

    TDataSet.RecNo Property
     
    Indicates the active record in the dataset.
     
    Class 
    TDataSet Syntax 
    [Delphi] property RecNo: Integer read GetRecNo write SetRecNo;
    Description 
    As implemented in TDataSet, the value of RecNo is always -1. Ordinarily an application does not access RecNo at the TDataSet level. Instead a re-implemented RecNo property in a descendant class such as TTable is accessed. RecNo provides a fallback property for derived datasets that do not support record numbers.
     
    =======================================================
    adoquery.cursorlocation := clUseClient
    使用客户端游标,可以获得记录集的记录数,使用服务端游标,就无法得到记录集的记录数。还属性与RecNo 无关。
      

  6.   

    谢谢楼上的大侠。如果再使用一个clientDateSet的话效率收到很慢啊。