[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Copy typed dataset content and update references accordingly

Posted on 2009-05-05
4
Medium Priority
?
691 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Learn Veeam advantages over legacy backup

Every day, more and more legacy backup customers switch to Veeam. Technologies designed for the client-server era cannot restore any IT service running in the hybrid cloud within seconds. Learn top Veeam advantages over legacy backup and get Veeam for the price of your renewal

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

656 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