Mehmet
Mehmet

Reputation: 2288

inner join with DataTables

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?

Upvotes: 2

Views: 5272

Answers (2)

Lloyd
Lloyd

Reputation: 2942

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

Upvotes: 0

James Hill
James Hill

Reputation: 61872

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);

Upvotes: 2

Related Questions