告诉你个思路: 1、在选择操作的时候记录ID号(唯一标识); 2、累计ID号,多选时需要记录。 3、最后操作的时候,只要DELETE FROM TABLENAME WHERE ID=ID1 OR ID=ID2……
DBGrid里不是有多行选择吗?选择多行后,再删除不就行了。
for j:=0 to dbgrid1.SelectedRows.Count-1 do begin data_str:=''; adoquery1.GotoBook(pointer(dbgrid1.SelectedRows.items[j])); for i:=0 to adoquery1.FieldCount-1 do begin if (i=2) or (i=3) then begin if dbgrid1.Fields[i].DisplayText='' then data_str:=data_str+dbgrid1.Fields[i].DisplayName+':'+'1900-01-01'+' ' else data_str:=data_str+dbgrid1.Fields[i].DisplayName+':'+dbgrid1.Fields[i].DisplayText+' '; end else data_str:=data_str+dbgrid1.Fields[i].DisplayName+':'+dbgrid1.Fields[i].DisplayText+' '; end; rywhfrm.DBMemo1.Lines.Add(data_str); end; 参考这个
没问题,FOLLOW ME! with DBGrid1.datasource.DataSet do begin setlength(lOprID,lCount); DisableControls; for i:=0 to lCount-1 do begin GotoBook(pointer(DBGrid1.SelectedRows.Items[i])); lOprID[i]:=fieldbyname('OprID').ASstring; end; FreeBookMark(GetBookMark); EnableControls; for i:=0 to lCount-1 do begin AdoCommDel.CommandText:='delete * from OprLog where OprID='''+lOprID[i]+''''; AdoCommDel.Execute; end; setlength(lOprID,0); end;
1、在选择操作的时候记录ID号(唯一标识);
2、累计ID号,多选时需要记录。
3、最后操作的时候,只要DELETE FROM TABLENAME WHERE ID=ID1 OR ID=ID2……
begin
data_str:='';
adoquery1.GotoBook(pointer(dbgrid1.SelectedRows.items[j]));
for i:=0 to adoquery1.FieldCount-1 do
begin
if (i=2) or (i=3) then
begin
if dbgrid1.Fields[i].DisplayText='' then
data_str:=data_str+dbgrid1.Fields[i].DisplayName+':'+'1900-01-01'+' '
else
data_str:=data_str+dbgrid1.Fields[i].DisplayName+':'+dbgrid1.Fields[i].DisplayText+' ';
end
else
data_str:=data_str+dbgrid1.Fields[i].DisplayName+':'+dbgrid1.Fields[i].DisplayText+' ';
end;
rywhfrm.DBMemo1.Lines.Add(data_str);
end;
参考这个
with DBGrid1.datasource.DataSet do
begin
setlength(lOprID,lCount);
DisableControls;
for i:=0 to lCount-1 do
begin
GotoBook(pointer(DBGrid1.SelectedRows.Items[i]));
lOprID[i]:=fieldbyname('OprID').ASstring;
end;
FreeBookMark(GetBookMark);
EnableControls;
for i:=0 to lCount-1 do
begin
AdoCommDel.CommandText:='delete * from OprLog where OprID='''+lOprID[i]+'''';
AdoCommDel.Execute;
end;
setlength(lOprID,0);
end;