Quote:
it is also creating a cloumn names IdentificationID in the UI which I don't need
But if you look carefully at the value in that column it is
0.
If you also examine the contents of
tableSet.Tables[1]
, it also has this "un-needed" column
Identification_Id
and it also has a value of 0.
It becomes more apparent what that extra column is doing if you change your XML to be
<school>
<Identification rollno="01">
<Information Name="ABC" Age="21" Sex="M" />
</Identification>
<Identification rollno="02">
<Information Name="BCD" Age="22" Sex="F" />
</Identification>
</school>
Now look at the
two datatables in the dataset ... Identification_Id = 0 matches up your original data and Identification_Id = 1 matches up the rows with my new data item.
So you can JOIN the two data tables together like this
var dt1 = tableSet.Tables[0];
var dt2 = tableSet.Tables[1];
var res = (from t1 in dt1.AsEnumerable()
join t2 in dt2.AsEnumerable() on (int) t1["Identification_Id"] equals (int) t2["Identification_Id"]
select new
{
rollno = t1["rollno"],
Name = t2["Name"],
Age = t2["Age"],
Sex = t2["Sex"]
}).ToList();
or if you prefer this format...
var res = dt1.AsEnumerable()
.Join(dt2.AsEnumerable(), t1 => (int) t1["Identification_Id"], t2 => (int) t2["Identification_Id"],
(t1, t2) => new
{
rollno = t1["rollno"],
Name = t2["Name"],
Age = t2["Age"],
Sex = t2["Sex"]
}).ToList();
You've mentioned DataGrid in your tags so you could just use
dataGrid1.DataSource = res;
Or if you really do want a DataTable as a result you can do something like
var resultTable = new DataTable();
resultTable.Columns.Add("rollno");
resultTable.Columns.Add("Name");
resultTable.Columns.Add("Age");
resultTable.Columns.Add("Sex");
foreach (var i in res)
resultTable.Rows.Add(i.rollno, i.Name, i.Age, i.Sex);
remembering to handle any null values if you need to.