procedure TForm3.Button2Click(Sender: TObject);
begin
adoquery1.Edit;
adoquery1.Close;
adoquery1.SQL.Clear;
adoquery1.SQL.Add('select * from fs where xh="'+dbtext1.Caption+'"');
adoquery1.open;
adoquery1.Active:=true;
if str<>'' then
adoquery1.FieldByName('str').AsString:=str;
end;我是delphi新手,不知道为什么出在哪里?一按确定就弹出dataset not in edit or insert mode
哪位大哥可以帮我解决一下

解决方案 »

  1.   


    procedure TForm3.Button2Click(Sender: TObject); 
    begin 
    adoquery1.Close; 
    adoquery1.SQL.Clear; 
    adoquery1.SQL.Add('select * from fs where xh="'+dbtext1.Caption+'"'); 
    adoquery1.open; 
    adoquery1.Edit; 
    if str <>'' then 
    adoquery1.FieldByName('str').AsString:=str; 
    end; 
      

  2.   


    procedure TForm3.Button2Click(Sender: TObject); 
    begin 
      adoquery1.Close; //等同于 adoquery1.Active:=false; 
      adoquery1.SQL.Clear; 
      adoquery1.SQL.Add('select * from fs where xh="'+dbtext1.Caption+'"'); 
      adoquery1.open; //等同于 adoquery1.Active:=true; 
      if str <>'' then
      begin 
        adoquery1.FieldByName('str').AsString:=str; 
        adoquery1.Post;
      end;
    end; 
      

  3.   

    顺序搞错了!如果要对数据进行修改,必须先要打开数据源,这样才可以进行操作!不然是不可以对数据进行edit,Append等操作的!希望人兄好好学习一下Ado控件的使用!
      

  4.   

    procedure TForm3.Button2Click(Sender: TObject); 
    begin 
      adoquery1.Close; //等同于 adoquery1.Active:=false; 
      adoquery1.SQL.Clear; 
      adoquery1.SQL.Add('select * from fs where xh="'+dbtext1.Caption+'"'); 
      adoquery1.open; //等同于 adoquery1.Active:=true; 
      if str <>'' then
      begin 
        adoquery1.Edit; //进入编辑状态
        adoquery1.FieldByName('str').AsString:=str; //也可以写成adoquery1['str']:=str;
        adoquery1.Post; //保存编辑结果
      end;
    end; 
      

  5.   


    对不起,少了一个 Edit
    procedure TForm3.Button2Click(Sender: TObject); 
    begin 
      adoquery1.Close; //等同于 adoquery1.Active:=false; 
      adoquery1.SQL.Clear; 
      adoquery1.SQL.Add('select * from fs where xh="'+dbtext1.Caption+'"'); 
      adoquery1.open; //等同于 adoquery1.Active:=true; 
      if str <>'' then
      begin 
        adoquery1.Edit;
        adoquery1.FieldByName('str').AsString:=str; 
        adoquery1.Post;
      end;
    end; 
      

  6.   

    procedure TForm3.Button2Click(Sender: TObject); 
    begin 
      adoquery1.Close; //等同于 adoquery1.Active:=false; 
      adoquery1.SQL.Clear; 
      adoquery1.SQL.Add('select * from fs where xh="'+dbtext1.Caption+'"'); 
      adoquery1.open; //等同于 adoquery1.Active:=true; 
      if str <>'' then
      begin 
        adoquery1.Edit;//如果你想做插入动作的话这里改为 adoquery1.append
        adoquery1.FieldByName('str').AsString:=str; 
        adoquery1.Post;
      end;
    end;