在窗体上放一个table,query,两个datasource,一个edit,一个dbedit,一个button,一个dbgrid组件,我想完成这样的功能:在edit组件中输入要查询的相关信息,点击button在DBGRID和DBEDIT组件中显示相关的数据资料,然后在DBEDIT组件中修改相关的资料,请大家帮我看看我的代码对么:
procedure TForm1.Button1Click(Sender: TObject);
begin
  if not table1.Locate('姓名',edit1.Text,[locaseinsensitive]) then
  showmessage('没有这个人!')
  else
  begin
  query1.Close;
  query1.ParamByName('name').AsString:=edit1.Text;
  query1.Open;
  end;
  table1.FieldByName('姓名').AsString:=query1.FieldByName('姓名').AsString;  table1.Edit;
  table1.FieldByName('姓名').AsString:=dbedit1.Text;
  table1.Post;
 
  query1.ParamByName('姓名').AsString:=dbedit1.Text;
  end;
我一运行就提示说'table1:dataset not in insert or edit mode'我不知道是那里错了啊??请大家教我!!:) 
(最好能附上代码!!!!谢谢了!!)

解决方案 »

  1.   

    procedure TForm1.Button1Click(Sender: TObject);
    begin
      if not table1.Locate('姓名',edit1.Text,[locaseinsensitive]) then
      showmessage('没有这个人!')
      else
      begin
      query1.Close;
      query1.ParamByName('name').AsString:=edit1.Text;
      query1.Open;
      end;  table1.edit; ////這里要 加
      table1.FieldByName('姓名').AsString:=query1.FieldByName('姓名').AsString;  table1.Edit;
      table1.FieldByName('姓名').AsString:=dbedit1.Text;
      table1.Post;
     //query1是一個只讀數據集﹐最好不要這樣用。
      query1.ParamByName('姓名').AsString:=dbedit1.Text;
      end;
      

  2.   

    TO: bbs791109(小别)
    table1.edit; ////這里要 加??????
    要加什么啊??
      

  3.   

    把QUERY的requestLive属性改为True使使!
      

  4.   

    关加EDItable1.FieldByName('姓名').AsString:=query1.FieldByName('姓名').AsString;
      

  5.   

    他显示的是query的field中没有‘姓名’这个字段啊~!!!!!
      

  6.   

    这里要加指的就是加 Table1.Edit;
    真是晕~~~~~~~~~~~~~~~~~~~~~~
      

  7.   

    你的Query的SQL语句是怎么写的?还是就没有语句?
    query1.Close;
    ??
    query1.ParamByName('name').AsString:=edit1.Text;
    query1.Open;
    ////////////////////////////////////////
    procedure TForm1.Button1Click(Sender: TObject);
    begin
      if not table1.Locate('姓名',edit1.Text,[]) then
      showmessage('没有这个人!')
      else
      begin
      query1.Close;
      query1.SQL.Clear;  //这里!!
      query1.SQL.Add(''); //这里!!
      query1.ParamByName('name').AsString:=edit1.Text;
      query1.Open;
      end;
      table1.Edit;  
      table1.FieldByName('姓名').AsString:=query1.FieldByName('姓名').AsString;  //table1.Edit;//这里不需要!!
      table1.FieldByName('姓名').AsString:=dbedit1.Text;
      table1.Post;
     
      query1.ParamByName('姓名').AsString:=dbedit1.Text;//??
      end;
      

  8.   

    sql语句自然是已经写好了!而且当query组件的ACTIVE属性为TRUE时,可以正常显示数据!
      

  9.   

    query1.ParamByName('姓名').AsString:=dbedit1.Text;//??这句话出的毛病,Query不可以赋值的,如果真的需要这方面的操作,我知道的有两种方法,1是设置它的RequestLive=True,不过要看你连的数据库类型,有的不支持的,比如DB2。
    2.加一个UpdateSQL控件,并且将Query的ChachedUpdates=True