Board index » delphi » Copying one record from one table to another

Copying one record from one table to another

I need to copy a record from one table to another.  The structures are the
same.  What is the easiest way to do this?  Currently I am just populating
the record field by field. Any suggestions?

Seth

 

Re:Copying one record from one table to another


S,

with Table1 do
begin
   Table2.AppendRecord(FieldByName('One').AsString,
FieldByName('Two').AsString)
end;

However doing it field by field is not a bad thing either as the above
example does not take into account the situation where field order
could change. You could also have a look at the TBatchMove component
that comes with Delphi.

HTH's

On Tue, 19 Oct 1999 11:58:00 -0500, "Seth Ricard"

Quote
<sric...@docpublish.com> wrote:
>I need to copy a record from one table to another.  The structures are the
>same.  What is the easiest way to do this?  Currently I am just populating
>the record field by field. Any suggestions?

>Seth

--Donovan

Donovan J. Edye  [www.edye.wattle.id.au/hobbies/prog/delphi/]
Namadgi Systems, Delphi Developer
Web: www.namsys.com.au
E-Mail: dono...@namsys.com.au
TVisualBasic := Class(None);

Re:Copying one record from one table to another


procedure AssignRow(Source, Destination : TDataSet);
var
  i : integer;
begin
  Destination.Append;
  for i := 0 to Source.FieldCount - 1 do
    if Destination.FieldDefs.IndexOf(Source.Fields{i].FieldName) > -1 then
      Destination.FieldByName(Source.Fields{i].FieldName).Value :=
Source.Fields{i].Value;
  Destination.Post;
end;

Works in D3 and above.

John Elrick

Quote
Seth Ricard <sric...@docpublish.com> wrote in message

news:7ui7it$ljo6@forums.borland.com...
Quote
> I need to copy a record from one table to another.  The structures are the
> same.  What is the easiest way to do this?  Currently I am just populating
> the record field by field. Any suggestions?

> Seth

Re:Copying one record from one table to another


Which is the fastest way to do this?
I am having problems with efficiency and maybe one of this ways is rapidly

Thanks in advance.

Roberto Martinez
LOMA Software

Quote
Seth Ricard wrote:
> I need to copy a record from one table to another.  The structures are the
> same.  What is the easiest way to do this?  Currently I am just populating
> the record field by field. Any suggestions?

> Seth

Re:Copying one record from one table to another


Quote
>I need to copy a record from one table to another.  The structures are the
>same.  What is the easiest way to do this?  Currently I am just populating
>the record field by field. Any suggestions?

Function CopyARecord(tblSource:Ttable;tblDest:ttable):Boolean;
var
  li,liFlds:  Integer;
begin
  tblDest.append;
  liFlds := tblSource.FieldCount - 1;
  for li := 0 to liFlds do Begin
    tblDest.FieldByName(tblSource.Fields[li].fieldName).Assign(
      tblSource.FieldByName(tblSource.Fields[li].fieldName));
  end;
end;
--
Brian Bushay (TeamB)
Bbus...@NMPLS.com

Other Threads