Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: Copy data from dataset to another with copied records marked for insert


This question is not answered. Helpful answers available: 2. Correct answers available: 1.


Permlink Replies: 4 - Last Post: Apr 18, 2018 6:57 AM Last Post By: Mark Williams
Mark Williams

Posts: 120
Registered: 5/8/10
Copy data from dataset to another with copied records marked for insert  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Apr 5, 2018 8:06 AM
I am looking for a fast way to copy all records in one FDQuery to another FDQuery, but I would need the copied records to be marked as usInserted so they will be inserted as new records into the database. Is this possible or do I have to copy on a record by record basis from one query to the other?
Francisco Arman...

Posts: 11
Registered: 3/3/01
Re: Copy data from dataset to another with copied records marked for insert  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Apr 18, 2018 5:37 AM   in response to: Mark Williams in response to: Mark Williams
Mark Williams wrote:
I am looking for a fast way to copy all records in one FDQuery to another FDQuery, but I would need the copied records to be marked as usInserted so they will be inserted as new records into the database. Is this possible or do I have to copy on a record by record basis from one query to the other?

Check CopyDataSet Method:
http://docwiki.embarcadero.com/Libraries/Tokyo/en/FireDAC.Comp.DataSet.TFDDataSet.CopyDataSet
Mark Williams

Posts: 120
Registered: 5/8/10
Re: Copy data from dataset to another with copied records marked for insert  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Apr 18, 2018 6:16 AM   in response to: Francisco Arman... in response to: Francisco Arman...
Francisco Armando Dueñas Rodriguez wrote:
Mark Williams wrote:
I am looking for a fast way to copy all records in one FDQuery to another FDQuery, but I would need the copied records to be marked as usInserted so they will be inserted as new records into the database. Is this possible or do I have to copy on a record by record basis from one query to the other?

Check CopyDataSet Method:
http://docwiki.embarcadero.com/Libraries/Tokyo/en/FireDAC.Comp.DataSet.TFDDataSet.CopyDataSet

is there a way of calling CopyDataSet so that the records it copies to the destination table are treated as new records rather than copies?
Robert Triest

Posts: 687
Registered: 3/24/05
Re: Copy data from dataset to another with copied records marked for insert  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Apr 18, 2018 6:39 AM   in response to: Mark Williams in response to: Mark Williams
is there a way of calling CopyDataSet so that the records it copies to the destination table are treated as new records rather than copies?
But how does your table know that they are copies??

I would not depend on a component-framework to copy data but only sql.
In your case I would use FDQuery just to do the insert sql:
.
https://www.w3schools.com/sql/sql_insert_into_select.asp

and then refresh your screen of your copy table with a Select sql..
Mark Williams

Posts: 120
Registered: 5/8/10
Re: Copy data from dataset to another with copied records marked for insert  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Apr 18, 2018 6:57 AM   in response to: Robert Triest in response to: Robert Triest
Robert Triest wrote:
is there a way of calling CopyDataSet so that the records it copies to the destination table are treated as new records rather than copies?
But how does your table know that they are copies??

I am not sure. However, if you do a CopyDataSet and then change the data in one of the records, it causes the original record to be updated. It doesn't insert a new record, so it would appear to know.


I would not depend on a component-framework to copy data but only sql.
In your case I would use FDQuery just to do the insert sql:

Unfortunately, I don't want to insert the records initially. The copies are presented to the user in a new grid and they are given the option of inserting them if they so choose or simply cancelling. This could amount to quite a lot of data so I don't do a massive insert only to have to delete all the records later.
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02