How to copy Data inside one table
How to copy Data inside one table
Hey,
I need to build a new row (containing numbers, blobs...) copying an old row and changing some values.
Is there any possibility to do this without using an SQL Query? I tried to use 2 TOraTables on the same table, but then I got a debugger exception (seems not to be considered to be used that way).
Is there an easy way to coyp Data from one row to another?
Thanks in advance,
Florian Fanderl
I need to build a new row (containing numbers, blobs...) copying an old row and changing some values.
Is there any possibility to do this without using an SQL Query? I tried to use 2 TOraTables on the same table, but then I got a debugger exception (seems not to be considered to be used that way).
Is there an easy way to coyp Data from one row to another?
Thanks in advance,
Florian Fanderl
Without sitting on my development-system:
Greetings
Jens
Code: Select all
dataset.insert;
dataset.fieldbyname('Field1').AsString := 'A';
dataset.fieldbyname('Field12').AsInteger := 3;
dataset.post;Jens
-
robert.wachtel
- Posts: 13
- Joined: Wed 12 Oct 2005 13:41
Code: Select all
procedure DuplicateCurrentRecord(aDataSet: TDataSet);
var
Data: array of variant;
aRecord: array of TVarRec;
i: integer;
max: integer;
begin
max := aDataSet.fields.count - 1;
// set the lenghth of the arecord array to be the same as the number of
// elements in the data array
SetLength(arecord, max + 1);
SetLength(data, max + 1);
// set the variant type pointers to the data array
for i := 0 to max do
begin
arecord[i].VType := vtVariant;
arecord[i].VVariant := @data[i];
end;
// Copy the Record to the Array
for i := 0 to max do
Data[i] := aDataSet.fields[i].value;
aDataSet.Insert;
aDataSet.SetFields(aRecord);
end;