How can I copy an entire table row to the same table

I have to copy a table row to a new row in the same table, but with a different key. Since I have seven of these tables, each with many fields, I don't want to do it one field at a time - not just because of the work, but also the maintainability. Is there a simple way to copy a row Even a "for each field (or column )" approach would be preferable to explicit code, but I don't know how to do that in this environment.

I'm using a Table Adapter and Binding Source for each table.



Answer this question

How can I copy an entire table row to the same table

  • PierreE

    Thanks you. It's an interesting suggestion. Of course, there are 6 child tables that need to be considered. I'm concerned about losing the linkages among these tables and the form to which they're bound. Also, I'm not quite clear on how you reassign a datatable to a binding source.
  • Craig Colomb

    You might have to create another temporary datatable. then using datatable.importrow looping to import the particular row you need. And reassign the datatable to the dataset/binding source again.

     



  • Pure Krome

    The way that I wound up doing this was to copy the old parent record to a new row and change the key. Then I just changed the keys on the child records to match the new parent. After that, I could delete the original parent record.
  • loureiro

    If your 6 tables had the relationship with each other, you might have to concern and plan properly for copying row. It would be very complicated.
    Just set the initial binding source of that control to nothing then, set it to the latest datatable will do.



  • uygar

    If I set the initial binding source to nothing and reset it, won't I also need to reset the B/S for the hundreds of controls that are bound to these tables
  • How can I copy an entire table row to the same table