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?

2 Answers 2

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);
Sign up to request clarification or add additional context in comments.

1 Comment

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.
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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.