十万火急请问大虾:
       如何实现在DELPHI中对SQL2000数据库中的记录进行自动累加,以及数据追加后的排序问题,现在数据库已经存在数据。
                                                万分谢谢

解决方案 »

  1.   

    你是说象产品编号一样自动生成??建立一个一个字段表  crno(maxno)保存最大编号一个过程
    create procedure xxx (@maxno integer output)
    as
    begin
      select @maxno=maxno from crno
      update crno set maxno=maxno+1;
    end返回一个参数给客户段delphi把@maxno和年份合起来插入数据库,可以保证多客户端不产生冲突
      

  2.   

    是这样的
    我的一个数据库需要自动产生一个数值,也就是类似与学生管理系统中的学号,我在输入一个学生的
    姓名后,他自动能够产生一个学号,列如:200400001 200400002 然后将他添加到我已经作好的数据中去,这样在查询的过程中我就可以按学号查询了,数据库中有一个名为学号的字段名称。数据库为SQL 非常谢谢关注
      

  3.   

    以前写过一个,看你能不能用:
    procedure Tpurin03.po01AfterInsert(DataSet: TDataSet);
    var now:SYSTEMTIME;
        s,sm:string;
        i,j,q:integer;
    begin
      getLocalTime(now);
      ADOQuery1.Close ;
      ADOQuery1.SQL.Clear ;
      ADOQuery1.SQL.Add('select max(poID) from po01 ');
      ADOQuery1.open;
      sm:=inttostr(now.wMonth);
      if length(sm)=1 then sm:='0'+sm;
      if ADOQuery1.fields[0].AsString<>'' then
      begin
        if sm=copy(ADOQuery1.fields[0].AsString,6,2) then
        begin
          s:=copy(ADOQuery1.fields[0].AsString,8,3);
          q:=strtoint(s)+1;
          i:=3-length(inttostr(q));
          s:=inttostr(q);
          for j:=1 to i do
          begin
            s:='0'+s;
          end;
          po01.Fields.FieldByName('poID').Asstring :='PO-'+copy(inttostr(now.wYear),3,2)+sm+s;
        end else
          po01.Fields.FieldByName('poID').Asstring :='PO-'+copy(inttostr(now.wYear),3,2)+sm+'001';
      end else
      begin
        po01.Fields.FieldByName('poID').Asstring :='PO-'+copy(inttostr(now.wYear),3,2)+sm+'001';
      end;
    end;