Solved

Copy typed dataset content and update references accordingly

Posted on 2009-05-05
4
678 Views
Last Modified: 2013-12-17
Hi,

The application I am working on is using typed datasets as business objects.
Now I need to create new object based on existing one.
The dataset contain 3 datatables, let say
 - Master
      MasterID
      Name

 - Data
      DataID
      MasterID
      SomeData

 - Layout
      LayoutID
      MasterID
      DataID
      SomeOtherData


So there is kind of three-way relationship exists: Each Layout record has reference to one Data record and both Data and Layout records reffering to the Master Record

My problem is to create a copy of the dataset (all 3 tables) with Layout records referring to NEWLY created Data records not to old ones.

Any idea how to do this?

P.S. The application is build with VS 2005 (.Net framework 2.0)
0
Comment
Question by:Michael_D
  • 2
4 Comments
 
LVL 13

Expert Comment

by:kaylanreilor
ID: 24311465
Probably you should use a "clone" method. Do you have details about the class that implement this business objects ?
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 24312195
The description is not very clear. Its clear about creating a copy but what you mean it should refer to newly created data objects?
0
 
LVL 13

Author Comment

by:Michael_D
ID: 24314875
>>> kaylanreilor
Clone or Copy methods will create exact copy of the object and will not change ID fields which will cause duplication errors in database since the ID fields should be unique.
The implementation is just generated dataSet object.

>>> CodeCruiser
here is a sample: let say I have this data

- Master
      MasterID      Name
      1                 Master 1

 - Data
      DataID      MasterID      SomeData
      1               1                 Data 1
      2               1                 Data 2

 - Layout
      LayoutID      MasterID      DataID      SomeOtherData
      1                 1                  1              Layout 1
      2                 1                  2              Layout 2
      3                 1                  2              Layout 3
   
Note: the Layout.DataID is FK into Data table and it could be more then one Layout record associated with one Layout Record

All Id fields are auto-increment fields

After copy I want have new record as following

- Master
      MasterID      Name
      2                 Copy of Master 1

 - Data
      DataID      MasterID      SomeData
      3               2                 Data 1
      4               2                 Data 2

 - Layout
      LayoutID      MasterID      DataID      SomeOtherData
      4                 2                  3              Layout 1
      5                 2                  4              Layout 2
      6                 2                  4              Layout 3

As you can see new records for Data and Layout are pointing now to MasterId= 2 (new record)
But this is not an issue as I can create copy of Master first, grab the new Id and then in loop create copy of Data records replacing MasterId with new Id.
The problem is how to create Layout records that linked to correct Data record (to the new one)

I hope this is clarify my intention.

0
 
LVL 13

Accepted Solution

by:
Michael_D earned 0 total points
ID: 24316898
Ok I found a solution.

I am first looping through Data rows and insert new records into DB. The new Ids is stored in the dictionary with oldId as a key.
When I am looping through layout rows I replace the DataId with the value from dictionary.

Kind of silly but it works.

Thanks for participating
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now