用QUERY查出一张表的数据,并在dbgrid(连接datasource)中显示,现在我要删除一条选中的数据并返回数据库.
请问如何写代码,谢谢高手!

解决方案 »

  1.   

    假若你的DATESET为adoquery1
    你选中那条记录。。
    先执行数据库删除:
    adoquery2.close;
    aqoquery2.sql.text:='delete from table where id='''+adoquery1.fieldbyname('id').asstring+'''';
    aqoquery2.execute;然后再删除DBGRID中的。
    adoquery1.delete;
      

  2.   

    dbgrid.datasource.dataset.edit;
    dbgrid.datasource.dataset.delete;
      

  3.   

    楼上的,你直接调用adoquery1.delete,那么删除DBGRID中的数据,同时也提交到数据库了
    楼主,你选中DBGRID中的数据,在按钮事件中
    procedure TForm1.btn1Click(Sender: TObject);
    begin
      adoquery1.delete;
    end;
    就一切OK了!
      

  4.   

    dinglinger(红辣椒) 
    没听说删除数据要先置EDIT状态
      

  5.   

    Examine State to determine the current operating mode of the dataset. 
    ......
    Posting or canceling edits, insertions, or deletions, changes State from its current state to dsBrowse. Closing a dataset changes its state to dsInactive.