自己写个过程,如果有KeyField或避免重复则列出并用';'或','号隔开,如果没有,vfield=''可以这样rocedure CheckData(SourceDataSet,TagDataSet:TDataSet;vField:string);vari,j,iFieldCount:Integer;sFields:Tstrings;TmpAdoDataSet:TAdoDataSet;Fieldvalue:OleVariant;CurrBook:TBytes;begin if vField='' then begin if SourceDataSet.RecordCount>0 then begin CurrBook:=TagDataSet.GetBookMark;//保留目标表中的记录位置 SourceDataSet.First; for i:=0 to SourceDataSet.RecordCount-1 do begin TagDataSet.edit; TagDataSet.Append; for j:=0 to TagDataSet.FieldCount-1 do begin //如果字段顺序一致 TagDataSet.Fields[j].Value:=SourceDataSet.Fields[j].value; //如果字段顺序不一致 //TagDataSet.Fields[j].Value:=SourceDataSet.FieldbyName(TagDataSet.Fields[j].FieldName).value; end; SourceDataSet.Next; end; TagDataSet.gotoBookMark(CurrBook);//加到原来记录处 TagDataSet.FreeBookMark(CurrBook);//释放书签 end; end; else begin sFields:=TStringList.Create; ExtractStrings([';',','],[':',' '],PwideChar(VField),sFields); iFieldcount:=sFields.Count; Fieldvalue := VarArrayCreate([0,iFieldcount-1],varVariant); //生成动态数组 Currbook:=DataSet.GetBookmark; TmpAdoDataSet:=TAdoDataSet.Create(nil); TmpAdoDataSet.clone(SourceDataSet,ltunspecified); if TmpAdoDataSet.RecordCount>0 then begin TmpAdoDataSet.First; while not (TmpAdoDataSet.Eof) do begin for j := 0 to iFieldcount - 1 do Fieldvalue[j] := SourceDataSet.FieldByName(sFields[j]).Value;//赋值给动态数组以比较是否已存在该记录 if (TagDataSet.Locate(vField, Fieldvalue, [])) then begin TmpAdoDataSet.Delete; end; TmpAdoDataSet.Next; end; end; if TmpAdoDataSet.RecordCount>0 then//还有不同的记录 begin TmpAdoDataSet.first; begin for I := 0 to TmpAdoDataSet.RecordCount - 1 do begin tagDataSet.Edit; tagDataSet.Append; for j := 0 to TagAdoDataSet.FieldCount - 1 do begin if TagDataSet.Fields.FieldKind=fkData then begin if not TagDataSet.Fields.ReadOnly then begin tagDataSet.Fields.Value:=TmpAdoDataSet.Fields.Value; end else begin tagDataSet.Fields.ReadOnly:=False; tagDataSet.Fields.Value:=TmpAdoDataSet.Fields.Value; tagDataSet.Fields.ReadOnly:=True; end; end; end; TmpAdoDataSet.Next; end; tagDataSet.GotoBookmark(CurrBook); tagDataSet.FreeBookmark(CurrBook); tmpAdoDataSet.Free; end; end;