DataSet.Merge question

  • Thread starter Thread starter Jiho Han
  • Start date Start date
J

Jiho Han

I have a dataset loaded with an xml that looks like this:

<associations xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<association>
<associationid>{8a3aca06-a7de-41a5-b584-063e7cf391bb}</associationid>
<createdon>2004-02-17T12:05:40.3430000-05:00</createdon>
<modifiedon>2004-02-17T12:05:40.3430000-05:00</modifiedon>
<forwardrelation>Parent</forwardrelation>
<backrelation>Parent</backrelation>
<forwardnotes>ttt</forwardnotes>
<backnotes/>
<fromid name="" dsc=""
type="1">{8c4a969b-2aa4-4679-b170-d9f6441f7c6d}</fromid>
<toid name="" dsc="" type="2">{df3f306f-19de-4f50-9784-623bf6693fa8}</toid>
<createdby name="" dsc=""
type="8">{2479254f-1dee-41dc-b79b-8de686a4db29}</createdby>
<modifiedby name="" dsc=""
type="8">{2479254f-1dee-41dc-b79b-8de686a4db29}</modifiedby>
</association>
</associations>

Then I try to merge another dataset loaded with another xml:

<resultset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<contact>
<contactid>{1323159A-E579-4A9B-95A2-5F9AFC041E28}</contactid>
<fullname>Jones, Sally</fullname>
<jobtitle>Lawyer</jobtitle>
<accountid name="Jones&amp;Jones"
dsc="0">{EE22734B-F1A1-4B0F-B874-52FE2A3B1A6A}</accountid>
</contact>
<contact>
<contactid>{DF3F306F-19DE-4F50-9784-623BF6693FA8}</contactid>
<fullname>Dodd, Cindy</fullname>
<jobtitle>Owner</jobtitle>
<accountid name="Suburban Cycle Shop"
dsc="0">{D17A8F20-D1D0-4F51-B365-92FDF16EDBE9}</accountid>
</contact>
<contact>
<contactid>{54B82B18-D54D-4B6B-B114-73093D2A0070}</contactid>
<fullname>Hayes, Scott</fullname>
<jobtitle>Primary Owner</jobtitle>
<accountid name="A&amp;M"
dsc="0">{3ABC2121-5315-4050-838D-477E04B37CE7}</accountid>
</contact>
<contact>
<contactid>{8929CAD1-E941-4B6E-AAB7-A3D3062A9C71}</contactid>
<fullname>Kennedy, Susan</fullname>
<jobtitle>Finance Workout</jobtitle>
<accountid name="A&amp;M"
dsc="0">{3ABC2121-5315-4050-838D-477E04B37CE7}</accountid>
</contact>
<contact>
<contactid>{AADC8B14-27F3-4B03-8901-FC0929D48544}</contactid>
<fullname>Block, Larry</fullname>
<jobtitle>Sales Turnaround</jobtitle>
<accountid name="A&amp;M"
dsc="0">{3ABC2121-5315-4050-838D-477E04B37CE7}</accountid>
</contact>
</resultset>

Using the following syntax:

associationDS.Merge(resultDS.Tables[0]); // assume the first xml has been
loaded into associationDS and the second into resultDS

There were no schemas involved and each DataSet is loaded via
ReadXml(XmlTextReader) method.
Things kind of work out ok as <contact> nodes are inserted right under
<associations> root so that it looks like:

<associations
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><association/><contact
/></assocations>

The only problem is that the resulting xml after the merge is missing
<accountid> node under <contact>.
What am I missing? Do I have to specify explicit schema info or
relationship - note that <association> and <contact> are seemingly
independant - ?

Thanks much!
Jiho
 
Hi Jiho
I have tried to simulate your problem and I used your 2 xml file.
The file that resulted was as you said
The thing is the account id field has two attributes so it is treated as
a separate data table so if you do the merge with
associationDS.Merge(resultDS.Tables[1]);
instead of
associationDS.Merge(resultDS.Tables[0]);
you will be find that only the account id will be added to the new files
so either you flatten the account id field or you create a schema file
for your xml files and chose the mode "enforce schema " while reading and
writing

AN EASY SOLUTION however is to write the merge command as follows
associationDS.Merge(resultDS);// without specifying any table
And this will solve your issue
 
Back
Top