Can a DataSet table be filled with data from two sources?
<p>I have a <code>DataSet</code> and read data from two sources in it. One table from a XML file and another table from a Firebird SQL database. What I try to get is only one table that has all columns from the XML file AND a few fields from the SQL data in a single table. Both tables have the same unique key field in it so it could be merged easily. I would like to bind all fields of this table to fields on a form.</p>

<p>Is it possible like described or do I not see that there is a simpler solution to my problem?</p>

<p><strong>Edit</strong>:
To show what I try to do a bit of extra code.</p>

<pre><code>DataSet dataSet = new DataSet();

DataTable table1 = new DataTable("test1", "test1");
table1.Columns.Add("id");
table1.Columns.Add("name");
table1.Columns[0].Unique = true;

table1.Rows.Add(new object[2] { 1, "name1" });
table1.Rows.Add(new object[2] { 2, "name2" });

DataTable table2 = new DataTable("test2", "test2");
table2.Columns.Add("id");
table2.Columns.Add("thing");
table2.Columns[0].Unique = true;

table2.Rows.Add(new object[2] { 1, "thing1" });
table2.Rows.Add(new object[2] { 2, "thing2" });

dataSet.Tables.Add(table1);
dataSet.Tables[0].Merge(table2, false);
</code></pre>

<p>When I run this code I get a <code>ConstraintException</code>. When I remove the unique on the <code>id</code> fields it fills the list with all the needed columns but one row with data from <code>table1</code> and another one with <code>table2</code> data. How can I merge them?</p>

<p><strong>Edit 2</strong>:
I tried to use the PrimaryKey solution as follows in live data.</p>

<pre><code>xmlData.Tables[0].PrimaryKey = new[] { xmlData.Tables[0].Columns["usnr"] };
dbData.PrimaryKey = new[] { dbData.Columns["usid"] };
xmlData.Tables[0].Merge(dbData, true, MissingSchemaAction.Add);
</code></pre>

<p>xmlData is a <code>DataSet</code> which comes from a XML file. It has id, usnr and a few other fields in it. dbData is a <code>DataTable</code> with data from db it has id, usid, name and a few other fields. The id fields are not relevant to my data. Both fields usnr and usid are strings in the table as I tested with <code>GetType()</code>.</p>

<p>When I now add <code>xmlData.Tables[0].Merge(dbData, true, MissingSchemaAction.Add);</code> it throws a <code>DataException</code></p>

<pre><code>&lt;target&gt;.ID and &lt;source&gt;.ID have conflicting properties: DataType property mismatch.
</code></pre>

<p>While writing this I realized that the id fields where different in both tables but I dont need them anyways so did remove the column before changing the primaryKey entries and merging. Now I get a <code>NullReferenceException</code> with no further information in it. The tables are all fine and have data in them, where could the Exception come frome now?</p>