在Delphi7中:
   假如当天的日期是2007-12-04,我想在Edit1.Text中取得当天的日期20071204,假如当天数据库没有数据就自动生成20071204001,假如有就和数据库比较,生成+1(既是说假如数据库有20071204001,那么Edit1.Text应该是20071204002).多谢指教!

解决方案 »

  1.   

     假如当天的日期是2007-12-04,我想在Edit1.Text中取得当天的日期20071204time:=formatdate(now(),'yymmdd')
    假如当天数据库没有数据就自动生成20071204001,假如有 就和数据库比较,生成+1(既是说假如数据库有20071204001,那么Edit1.Text应该是20071204002).
    select 字段名(20071204002) from 数据库 where 字段名 like '''+time+''%'假如有
    edit1.text:=floattostr((strtofloat(字段名)+1));
    如果没有
    edit1.text:='+time+'+'001';
      

  2.   

    Delphi[/code]
          假如当天的日期是2007-12-04,我想在Edit1.Text中取得当天的日期20071204,假如当天数据库没有数据就自动生成20071204001,假如有 
    就和数据库比较,生成+1(既是说假如数据库有20071204001,那么Edit1.Text应该是20071204002). 
    -------------------------------------------------------------------------------------------------------------------
    1:time:=formatdatetime('yyyymmdd',now()) ;
    2:至于第二个,自动生成那只有在timer时间里面写了,,,写法楼上已经说明,,
      

  3.   

    这个涉及到自动生成编号,建议在后台数据库中使用使用存储过程来实现.在程序代码中来实现,先查询下数据库,有就在后面依次自增编号
    没有就依据日期规则自动生成。写个函数,如下:function TForm1.Getid:string;
    var
       no:string;
       tmpno:integer;
    begin
        no:=formatdatetime('yyyymmdd',now()); //获取当前时间并格式化
        with adoquery1 do
        begin
            close;
            sql.clear;
            sql.add('select id from tablename where id like :tmpid order by id);
            parameters.ParamByName('tmpid').Value:=no+'%'; //通配符查询是否当天有
            open;
        end;
        if adoquery1.RecordCount<1 then
            result:=no+'001' //查询没有结果,生成为第一条编号
        else
            begin
                adoquery1.Last; //移动到记录最后
                tmpno:=strtoint(copy(adoqyery1.fieldbyname('id').AsString,9,3));
                result:=no+formatfloat('000',tmpno+1);
            end;
    end;
      

  4.   

    function GetNewLstNo(); string;
    var
      strSql: string;
    begin
      strSql := 'select max(voucher)  as mxVoucher from table where voucher like '''+FormatDateTime('yyyymmdd',Date)+'%''';
      OpenDataSet;   //打开记录集
      result := DataSet.FieldByName('mxVoucher').AsString;
      if result='' then result := FormatDateTime('yyyymmdd',Date)+'001'
      else result := FormatDateTime('yyyymmdd',Date)+Format('%0.3d',[StrToInt(RightStr(result),3)+1])
    end;
      

  5.   

    实现功能:取与数据库比较+1,没有就生成D200801190001(当天时间是2008-01-09)
    我也试过编写:但提示有问题,请各位指点:
    提示:AdoQuery:Rbianhao field not found! 
    var
     
      d,id,sql:string;
    begin  Adoquery.Close;
      Adoquery.SQL.Clear;
      d:='D'+formatdatetime('yyyymmdd',now);
      sql:='select max(convert(int,substring(RBianHao,10,4))) from Resume where RBianHao like ''D[0-9][0-9][0-9][0-9][0-9][0-9]%''';  Adoquery.sql.Add(sql);
      Adoquery.ExecSQL;
      id:=d+format('%0.4d',[Adoquery.fields[0].AsInteger+1]);
      Edit1.Text:=id;