我在ACCESS中建表如下:
id   filename      inserttime   accesstime     data
                                访问时间      是否已访问
我要从ACCESS数据库中顺序的将该记录拿出来访问,访问完后要将data的值改为true啊
我写的代码如下:
procedure TForm1.Button1Click(Sender: TObject);
begin
with adotable1 do
begin
  open;
  first;
    while not Eof do
    begin
    if adotable1.FieldByName('filename').AsString<>'' then
    begin
    ExecuteParser( stringreplace(Systemdir+adotable1.FieldValues['filename'],'/','\',[rfReplaceAll]));
    adotable1.Insert;
    adotable1.fieldbyname('accesstime').AsString:=datetimetostr(now());//记录访问时间
    adotable1.FieldByName('data').AsBoolean:=true; //将data值改为true
    adotable1.Post;
     Next;
    end;
    end;
end;
我想问高手们我这样插入的话,那不是将数据库中的所有记录都插入了访问时间和将data值都改为true了吗?
请问我怎样才能够将我访问的那条记录插入访问时间和更新data值啊
代码怎么写啊?

解决方案 »

  1.   

    我的执行结果是什么,我看应该是一口气把所有的记录全部写入了accsstime 和data付值为true呀  没明白你的执行要求是什么?  不过如果你要执行将某个特定的记录,你可以用主关键字段来进行比较比如: adotable1.fieldbyname('id')= 确定字段的值 。
      

  2.   

    对啊我就是要执行我访问了的那条记录 啊
    ‘insert into xml (accesstime) values (datetimetostr(now())) where 条件改怎么写啊?
    就是我怎么知道刚刚是访问的哪条记录啊
      

  3.   

    adotable1.Insert是新插入一个记录吧,如果是修改则adotable1.edit
      

  4.   

    ExecuteParser( stringreplace(Systemdir+adotable1.FieldValues['filename'],'/','\',[rfReplaceAll]));
        adotable1.Insert;
    改为    adotable1.Edit
      

  5.   

    ExecuteParser( stringreplace(Systemdir+adotable1.FieldValues['filename'],'/','\',[rfReplaceAll]));
        adotable1.Edit
    可以吗
      

  6.   

    我有点明白了楼主是不是说插入一条记录,ID是自增的插之前不知道这个ID,所以插入完了取不到刚才插入的那条了?
    可以用两个不重复的字段,一个做ID,一个做定位
      

  7.   

    procedure TForm1.Button1Click(Sender: TObject);
    begin
    with adotable1 do
    begin
      open;
      first;
        while not Eof do
        begin
        if adotable1.FieldByName('filename').AsString<>'' then
        begin
        ExecuteParser( stringreplace(Systemdir+adotable1.FieldValues['filename'],'/','\',[rfReplaceAll]));
        adotable1.Edit;////////////////////////////
        adotable1.fieldbyname('accesstime').AsString:=datetimetostr(now());//记录访问时间
        adotable1.FieldByName('data').AsBoolean:=true; //将data值改为true
        adotable1.Post;
         Next;
        end;
        end;
    end;