[求助] 自动产生编号的问题
各位好!我现在正在写一个电脑设备管理的小程序,在做新增电脑设备登记表时,想让程序自动产生编号,我写了一个,具体代码如下,现在只能问题是,怎样让编号在原来的基础上自动加1,现在自动显示的还是上个编号,请各位帮帮看看,谢谢!<BR>procedure TForm21.FormCreate(Sender: TObject);<BR>var<BR>d,id,sql:string;<BR>begin<BR> sql:='select max(id) as ss from [addsb]';<BR> adoquery1.Close;<BR> adoquery1.SQL.Clear;<BR> adoquery1.sql.Add(sql);<BR> adoquery1.Open;<BR> id:=adoquery1.fieldbyname('ss').AsString;<BR> if id=null then<BR> id:=inttostr(0)<BR> else<BR> d:=formatdatetime('yymmdd',now);<BR> edit1.Text:='XD'+d+id;<BR>end; procedure TForm21.FormCreate(Sender: TObject);<BR>var<BR>d,sql:string;<BR>id:integer;<BR>begin<BR>sql:='select max(id) as ss from [addsb]';<BR>adoquery1.Close;<BR>adoquery1.SQL.Clear;<BR>adoquery1.sql.Add(sql);<BR>adoquery1.Open;<BR>id:=adoquery1.fieldvalue['ss'];<BR>if id=null then<BR> id:=inttostr(0)<BR>else<BR>begin<BR> d:=formatdatetime('yymmdd',now);<BR> id:=id+1;<BR> end;<BR> edit1.Text:='XD'+datetimetostr(d)+inttostr(id);<BR>end;<BR> ///这样试试! <P>其实你在数据库中设计表时就可以指定自动加1的列。如果要程序实现,可以在添加数据行前先统计原有行数量,然后加1就是新行的编号了</P>页:
[1]
