一个主表,一个明细表,以字段MID字段关联,如果主表的一条记录对应明细表有5条记录,那么这5条记录的序号从1至5,5条记录之间不用区分顺序,主表的下一条记录对应明细表有7条记录,那么这7条记录的序号从1至7,如何写这个计算字段的语句,数据库用sqlserver2000,请指教,最好写出注解,行马上给分

解决方案 »

  1.   

    在DataSet的OnCalcFields事件中写如下代码:
    procedure TForm1.ADOQuery1CalcFields(DataSet: TDataSet);
    begin
      DataSet.FieldByName('计算字段').AsInteger := DataSet.RecNo;  // or DataSet.RecNo + 1
    end;不要说你不会创建计算字段
      

  2.   

    我在wwDbgrid中是在procedure TForm1.wwDBGrid1DrawDataCell(Sender: TObject; const Rect: TRect;
      Field: TField; State: TGridDrawState);
    var Y:integer;
    begin
       if field.FieldName='A' then
       begin
          wwdbgrid1.Canvas.TextOut(rect.Left,rect.Top ,inttostr(table1.RecNo));
       end;
    end;
    不用计算字段,但也得弄一个字段。
      

  3.   

    to noall()
    你的这个字段怎样弄,不是计算字段,又不可能是Data字段
      

  4.   

    因为这个是自己画出来的,所以就无所谓用那种类型的字段了(我是用字符型的)
    dbgrid就是在DrawDataCell事件里写了。你随便拿个表试试就知道了。
      

  5.   

    sqlserver 有一个bigint,可以用来做id,设置成主键,然后自增一.
      

  6.   

    同意顶楼wisenowa(127.0.0.1) 的方法
    up
      

  7.   

    select ID,(select count(*) from Item where ODIID = A.ODIID '+and ID <= A.ID ) as No from tem as A where A.ID='11' and OROID='22';