Hi All,
Is there an easy way to copy a record o the same table?
I have an SQLite database that the user may often want to have almost the same stuff in another record, and just change one or two fields.
Is there something like BatchMove that I can copy all but the AutoInc field? There are no no unique, cannot be blank etc conflicts.
I know I can write a
...fieldbyname.AsString = ...fieldbyname..
for something like 120 fields but would rather just use something like CopyRecord(tblFrom, tblTo
Thanks
Copy record to same table?
Copy record to same table?
Thanks
Dyslexic Bob
Dyslexic Bob
-
- Platinum Boarder
- Posts: 1962
- Joined: 17.01.2011, 14:17
hmmm - something like that:
The Blacklist is a list of the fields you don't want to copy. The Fields are separated by Semicolons...
Code: Select all
procedure copyfields(Src, Target: TDataSet; Blacklist: String);
var
x: Integer;
begin
Blacklist := ';' + Blacklist + ';';
for x := 0 to Src.Fields.Count do begin // iterate over all source fields
if Pos(';' + Src.Fields[x].FieldName + ';', Blacklist) <> 0 then begin //check if the Field is in the blacklist
Dst.FieldByName(Src.Fields[x].FieldName).Value := Src.Fields[x].Value;
end;
end;
end;
Thanks for going to that trouble, but I had already tried something like that and it would not copy the data to the new record. It created and empty record. Here's what I tried...
I finally got around it by creating a table at run time, Copying a record to it then back to the originating DataSet. That worked well.
Code: Select all
for i:=1 to tblFrom.FieldCount-1 do // Start from 1 to skip the AutoInc
begin
if tblTo.FindField(tblFrom.Fields[i].FieldName) <> nil then
begin
tblTo.FieldByName(tblFrom.Fields[i].FieldName).Value:=tblFrom.Fields[i].Value;
end;
end;
Thanks
Dyslexic Bob
Dyslexic Bob