Delphi and Kylix

Moderators: pritaeas
Number of threads: 7244
Number of posts: 19051

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
How to copy one single record Posted by ragaru on 26 Feb 2004 at 6:00 AM
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.

Report
Re: How to copy one single record Posted by ReplSoft on 29 Feb 2004 at 12:09 AM
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.
:
:

Report
Re: How to copy one single record Posted by softman on 2 Mar 2004 at 4:43 AM
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
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;


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




 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.