delphi刪除時特別注意

procedure TrklrFram.ado_shmainBeforeDelete(DataSet: TDataSet);
var
  i_sql, idstr: string;
  i: integer;
begin
  inherited;
  if ado_shmain.FindField('cSTATE').asstring <> '未提交' then
    Abort;
  if not myhs.Confirm1('確認要刪除嗎?') then
    Abort;
  i_sql := 'select  *  from  tf_sc_sqmx where mid=' + ansiquotedstr(ado_shmain.findfield('id').AsString, '''');
  OpenADODataset(maindm.QryPub, i_sql);
  if maindm.QryPub.RecordCount > 0 then
  begin
    with maindm.QryPub do
      for i := 1 to maindm.QryPub.RecordCount do
        idstr := maindm.QryPub.findfield('mid').AsString;
    with maindm.QryPub do
    begin
      Close;
      sql.Clear;
      sql.Text := 'DELETE FROM tf_sc_sqmx WHERE mid = ' + ansiquotedstr(idstr, '''');
      ExecSQL;
    end;
  end;
end;sql

相關文章
相關標籤/搜索