I have an interesting problem. I am trying to use the DataTable.Merge method - and running into a situation where it does not work.

I import two Excel spreadsheets into two DataTables - but I also change two columns in each imported table (the primary key for the data) - from double to Int32 while importing. I do this by creating a new column of Int32 - move the data into that column, delete the old column - and give the new Int32 column the name of the old column.

Here are the two original results in a grid... The one on the left contains a list of Personal Titles. The one on the Right contains the descriptions of those titles. You can see the Master ID and Sub Id fields are the keys to these tables.

enter image description hereenter image description here

When I try to merge the tables I get some very bad results. In the screen capture below - you can see how it has not merged the data properly. It has overwritten Master ID 1 with Master Id 12 from the second data table - and none of the Description values have been populated.


enter image description here

Now - if I take those data tables and save them out to XML (WriteXML method) - and import them - then run the same merge routine - I get what I would expect. from the merge method!!

enter image description here

So - my question is why is this happening?? It would seem that changing the field type is causing me some issues - and I cannot see why? Is there something else I need to change before I run the Merge method on the data tables?? Anyone out there run into something like this with Data Tables and the Merge (or other) method??

G Bradley MacDonald's user avatar

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.