First, you are probably wondering why I want to 'duplicate' data in the first place 
Well, it's actually necessary:
Currently, I am trying to find a nice efficient method to duplicate an order on our customer service order entry screen. The order entry program is connected to an MS SQL database and is written in C#.
Right now, our CSRs must re-enter by hand a new order that is identical to a previous order (Imagine a customer saying "Put in an order for the same product and quantity as last month"). This order table is linked to several child tables for both order and production purposes. Initially, I thought I needed to load in each row of every table that is linked to that order, create a new row for every existing row, and copy the data (minus the primary key) and retrieve the new primary key to use in the child tables. Very exhausting task.
Sounded like alot of work to me so I set out trying to figure out how to simply trick the program into changing the rowstate of every row to 'Added'. I could then simply change the order number , update the database (letting SQL assign new PKs), and voila! a duplicate set of rows in the database all constrained to each other yet seperate from the original order.
Unfortunately, I cannot do the above because no matter what I try, I cannot simply get the same rows only as 'Added'. What I do get is either A) Constraint exceptions from trying to change each individually or B) duplicate rows completely devoid of any relationship what-so-ever.
I hope I adequately explained my dilemma. I would post code, but I have yet to find any route of action to take other than the long hard path of rebuilding every row from the ground up (which I know would work).
"Why don't you just use that if you know it works?" you ask? Well, I figured this way I can apply the same methods to other applications and it would allow database changes without me having to re-compile this "copy order" form every time there is a new table added.
If anyone has ANY ideas. Please point me in a direction!
Thank You
Well, it's actually necessary:
Currently, I am trying to find a nice efficient method to duplicate an order on our customer service order entry screen. The order entry program is connected to an MS SQL database and is written in C#.
Right now, our CSRs must re-enter by hand a new order that is identical to a previous order (Imagine a customer saying "Put in an order for the same product and quantity as last month"). This order table is linked to several child tables for both order and production purposes. Initially, I thought I needed to load in each row of every table that is linked to that order, create a new row for every existing row, and copy the data (minus the primary key) and retrieve the new primary key to use in the child tables. Very exhausting task.
Sounded like alot of work to me so I set out trying to figure out how to simply trick the program into changing the rowstate of every row to 'Added'. I could then simply change the order number , update the database (letting SQL assign new PKs), and voila! a duplicate set of rows in the database all constrained to each other yet seperate from the original order.
Unfortunately, I cannot do the above because no matter what I try, I cannot simply get the same rows only as 'Added'. What I do get is either A) Constraint exceptions from trying to change each individually or B) duplicate rows completely devoid of any relationship what-so-ever.
I hope I adequately explained my dilemma. I would post code, but I have yet to find any route of action to take other than the long hard path of rebuilding every row from the ground up (which I know would work).
"Why don't you just use that if you know it works?" you ask? Well, I figured this way I can apply the same methods to other applications and it would allow database changes without me having to re-compile this "copy order" form every time there is a new table added.
If anyone has ANY ideas. Please point me in a direction!
Thank You