Here is an example, wich checks if the destination table contain the specifed field, and if it is, then copies the data. In the case, if the two table has different structure, but there are similar fields, the corresponding data will be copied. The DataFrom should contain the sorce table, and the DataTo (ttable) should contain the destination table. The procedure checks, for autoincrement field, 'cos readonly values cannot be copied, and in case exception may be raised.
with DataFrom do
for i:= 0 to FieldCount -1 do
if (DataTo.FindField(Fields[i].FieldName).DataType <> ftAutoinc) then
if not (DataTo.Fields.FindField(Fields[i].FieldName) = nil) then
DataTo.FieldByName(Fields[i].FieldName).AsString := FieldByName(Fields[i].FieldName).AsString;
I did not tested the code, but it supposed to work, or you can consider using insert SQL also.
: Copy a row (single record) by copying each cell.
: : I'd like to know how to copy one single record from a Table onto another Table with the same structure without having to filter the source Table.
: : Thanks in advance.