How to copy one single record - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

How to copy one single record

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.

Comments

  • ReplSoftReplSoft Posts: 23Member
    Copy a row (single record) by copying each cell.

    Alexey

    : 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.
    :
    :

  • softmansoftman Posts: 157Member
    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.

    [code]
    with DataFrom do
    begin
    DataTo.Append;
    for i:= 0 to FieldCount -1 do
    begin
    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;
    end;
    DataTo.Post;
    end;
    [/code]

    I did not tested the code, but it supposed to work, or you can consider using insert SQL also.

    softman


    : Copy a row (single record) by copying each cell.
    :
    : Alexey
    :
    : : 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.
    : :
    : :
    :
    :

Sign In or Register to comment.