2

I have two DataTables. I want to do inner join them into a new Data Table. There is no database access.

First columns of the Data Tables are key field.

 string ParentKeyColumn = dt1.Columns[0].ColumnName;
 string ChildKeyColumn = dt2.Columns[0].ColumnName;

Also I m using Devexpress components.

How can I do this?

Mehmet
  • 2,256
  • 9
  • 33
  • 47

2 Answers2

2

Take a look at this blog post on social.msdn.

Key details:

Define a primary key:

dt2.PrimaryKey = new DataColumn[] { dt2.Columns["Deptno"] };

Define a data relation and add it to your dataset:

DataRelation drel = new DataRelation("EquiJoin", dt2.Columns["Deptno"], dt1.Columns["Deptno"]);

ds.Relations.Add(drel);
James Hill
  • 60,353
  • 20
  • 145
  • 161
  • Thanks James. But I dont have unique columns. Im getting error at this line;dt2.PrimaryKey = new DataColumn[] { dt2.Columns["Deptno"] }; : These columns don't currently have unique values. – Mehmet Nov 12 '11 at 09:46
0

I would create the DataTable you require programatically and then load the data using LINQ as per the first of the following answers.

Using LINQ

Using Merge

From MSDN Forums

Community
  • 1
  • 1
Lloyd
  • 2,932
  • 2
  • 22
  • 18