首先设置 DBGrid1 Options属性中的 dgMultiSelect 为True;这样就可以多选了.
假设 ID 为表的主键吧
procedure TForm1.Button2Click(Sender: TObject);
var
iLoop: Integer;
sBH: string;
begin
sBH := '(';
for iLoop := 0 to DbGrid1.SelectedRows.Count - 1do
begin
AdoQuery1.GotoBookmark(pointer(DbGrid1.SelectedRows[iLoop]));
if iLoop <> Dbgrid1.SelectedRows.Count - 1 then
sBH := sBH + ' ID= ' + IntToStr(adoquery1['ID']) + ' or '
else
sBH := sBH + ' ID= ' + IntToStr(adoquery1['ID']);
end;
sBH := sBH + ')';
with AdoQuery2do
begin
close;
SQL.Text := 'select * from 表 where ' + sBH;
open;
end;
//以下可以利用AdoQuery2做打印了
end;