select count(*) as quan from table1 where fld = 'ddd' group by fld
在数据集的BeforePost事件中加 With Query1 do begin Close; SQL.Clear; SQL.Add('Select Count(*) as Count From Table Where KeyField=:KeyField'); ParamByName('KeyField').asString:=varKeyFiled; Open; if Count>0 then ShowMessage('数据重复'); Close; end;
With Query1 do begin
Close;
SQL.Clear;
SQL.Add('Select Count(*) as Count From Table Where KeyField=:KeyField');
ParamByName('KeyField').asString:=varKeyFiled;
Open;
if Count>0 then ShowMessage('数据重复');
Close;
end;
AdoQuery.Locate("Field1","Value1");支持多字段。
up
检查有没有重复的primary key,有就是重复,没有就insert。呵呵!!