你可以参考一下我这段代码:
我的表是jrq_personcode ,字段 person_code 相当你的ID,我是截取了时间来表示的!
----------
procedure TForm1.BitBtn1Click(Sender: TObject);
var str:string;
var Year,Month,Day,Hour, Min, Sec, MSec :word; yue,tian,shi,fen,miao:string;
begin
DecodeDate(date, Year, Month, Day);
DecodeTime(time, Hour, Min, Sec, MSec);
if Month<=9 then
yue:='0'+inttostr(Month) else yue:=inttostr(Month);
if Day<=9 then
tian:='0'+inttostr(Day) else tian:=inttostr(Day);
if Hour<=9 then
shi:='0'+inttostr(Hour) else shi:=inttostr(Hour);
if Min<=9 then
fen:='0'+inttostr(Min) else fen:=inttostr(Min);
if Sec<=9 then
miao:='0'+inttostr(Sec) else miao:=inttostr(Sec);
str:=' Select * into #Table From jrq_personcode Where person_code='+Edit3.Text //原来的ID
+' Update #Table Set person_code='+inttostr(Year)+yue+tian+shi+fen+miao //更新后的ID
+' Insert jrq_personcode Select * from #Table' //保存
+' drop table #Table'; /////////删除临时表 ,这句千万别忘了,不然会导致异常
ADOQuery1.Close;
ADOQuery1.SQL.Clear;
ADOQuery1.SQL.Add(str);
ADOQuery1.ExecSQL;
str:='select * from jrq_personcode';
ADOQuery1.Close;
ADOQuery1.SQL.Clear;
ADOQuery1.SQL.Add(str);
ADOQuery1.Open;
end;