一个adodataset与一个adocommand同时连接一个数据库。
dataset用于显示记录。command执行一条删除记录的sql语句。然后command.close。
为什么dataset的数据没有理新?删除的记录还存在。要关闭程序,再运行才能显示剩余的记录? 
至于为什么要分开用。不直接用adodataset删除记录,我也知道这样可以。可是现在问题出来了就应该解决、弄个明白,请大家不要再告诉我直接用adodataset删除的方法了。

解决方案 »

  1.   

    ADODataSet打开后就已经把数据下载到本地缓存了,所以你用别的数据集控件或别的方法删除数据,并不会使ADODataSet立即刷新,除非ADODataSet.Close;
    ADODataSet.Open;
      

  2.   

    这个题是因为本人没分了,所以麻烦cuiang (剑云天) 兄弟帮我问的。zzllabc(龙) 大歌说的方法我已经试过了。可是还是不行。
    type
    myaction:class;
    end;procedure myaction.delec(ado: tadodataset; id: integer);
    //删除大类的函数ado是连接bigtype表的记录集(adodataset控件)
    //id是大类的ID号
    var
    ADOCommand1: TADOCommand;
    begin
    if application.MessageBox('真的要删除这个大类吗?','询问',1)=1 then
    begin
    adocommand1:=Tadocommand.Create(nil);
    adocommand1.ConnectionString:=ado.ConnectionString;
    adocommand1.CommandText:='delete * from bigtype where id='+inttostr(id);
    adocommand1.Execute;
    adocommand1.Free;
    end;
    ado.close;
    ado.open;
    end;
    procedure myaction.showtreeview(ado:Tadodataset;treeview:TTreeView;imag:Timagelist);
    var
    newnode,tempnode:ttreenode;
    i:integer;
    begin
    ado.Close;
    ado.Open;
    treeview.Items.Clear;
    i:=0;while not ado.Eof do
      begin
      treeview.Images:=imag;
      treeview.Items.add(nil,ado.FieldByName('typename').asstring);
      newnode:=treeview.Items.Item[i];
      treeview.Items.Item[i].StateIndex:=ado.fieldbyname('id').Value;
      newnode.ImageIndex:=0;
      treeview.Items.AddChild(newnode,'纯文本信息');
      treeview.Items.Item[i+1].StateIndex:=ado.fieldbyname('id').Value;
      treeview.Items.Item[i+1].ImageIndex:=1;
      treeview.Items.AddChild(newnode,'其它文件类型');
      treeview.Items.Item[i+3].StateIndex:=ado.fieldbyname('id').Value;
      treeview.Items.Item[i+3].ImageIndex:=1;
      i:=i+3;
      ado.Next;
      end;
    end;//以上是两个比较关键的函数。
    //以下是删除按钮的点击事件。
    procedure TForm1.N4Click(Sender: TObject);
    var
    id:integer;
    s:myaction;
    begin
    id:=tv1.Selected.StateIndex;
    s.delec(adodataset1,id);
    s.showtreeview(adodataset1,tv1,imagelist1);
    end;
      

  3.   

    ado.close;
    ado.open;
    你的ado是什么呢?是adocommand吗?
    你的里面要有sql语句的'SELECT * from bigtype'
      

  4.   

    在函数里用
    ado.close;//ado是传过来的变值参数.
    ado.open;
    不行.
    procedure TForm1.N4Click(Sender: TObject);
    var
    id:integer;
    s:myaction;
    begin
    id:=tv1.Selected.StateIndex;
    s.delec(adodataset1,id);//删除记录的函数.
    adodataset1.close;
    adodataset1.open;
    s.showtreeview(adodataset1,tv1,imagelist1);//显示记录的函数.
    end;
    这样也是没有立即更新.
      

  5.   

    不会吧你是不是哪里用了事物没有COMMIT啊
      

  6.   

    做一个    ADODataSet1.Refresh 的动作试试。