for example:procedure PostData; var i:integer; sSQL:string; begin sSQL := ''; with StringGrid1 do for i:=1 to Count -1 do begin if SameText(Cells[0,i], '') then //假设第0列存储ID字段 sSQL := sSQL + 'INSERT INTO MyTable (...) VALUES (...)' //构建批量SQL语句 else sSQL := sSQL + 'UPDATE MyTable SET ... WHERE ID = ' + Cells[0,i]; end;
with ADOQuery1 do begin Close; SQL.Text := sSQL; Prepared; ExecSQL; Close; end;end;
var
i:integer;
sSQL:string;
begin
sSQL := '';
with StringGrid1 do
for i:=1 to Count -1 do
begin
if SameText(Cells[0,i], '') then //假设第0列存储ID字段
sSQL := sSQL + 'INSERT INTO MyTable (...) VALUES (...)' //构建批量SQL语句
else
sSQL := sSQL + 'UPDATE MyTable SET ... WHERE ID = ' + Cells[0,i];
end;
with ADOQuery1 do
begin
Close;
SQL.Text := sSQL;
Prepared;
ExecSQL;
Close;
end;end;