在线求问:如何知道Select语句返回结果中的行号?
如:select no,* from table1
          1   aaa
          2   bbb
          3   ccc
          .   ...
no 为每条记录的记录编号

解决方案 »

  1.   

    query.fieldbyname('no').asinteger 就是了
      

  2.   

    添加一个identity(1,1),max()这个字段。
      

  3.   

    我用的是sqlserver,希望有某函数能生成上述结果集。但不希望创建新表。
      

  4.   

    用recno就可以;
    介绍个实例给你参考;
    procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
      DataCol: Integer; Column: TColumn; State: TGridDrawState);
    begin
      if column.Index = 0 then
      begin
          with dbgrid1.Canvas do
          begin
              fillrect(rect);
              textout(rect.Left + 2, rect.Top + 2,inttostr(adoquery1.RecNo));
          end;
      end;
    end;