Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to union two data tables and order the result

Q: If I have two DataTables like this :

Dt1(emp_num,emp_name,type)

Dt2(emp_num,emp_name,type)

I wanna to Union them and order the result by emp_name.

like image 950
Anyname Donotcare Avatar asked Jan 03 '12 10:01

Anyname Donotcare


People also ask

How do you compare two data tables?

Compare two tables by using joins. To compare two tables by using joins, you create a select query that includes both tables. If there is not already an existing relationship between the tables on the fields that contain the corresponding data, you create a join on the fields that you want to examine for matches.

How do I merge two data tables in R?

To join two data frames (datasets) vertically, use the rbind function. The two data frames must have the same variables, but they do not have to be in the same order. If data frameA has variables that data frameB does not, then either: Delete the extra variables in data frameA or.


2 Answers

var dt1 = new DataTable(); // Replace with Dt1
var dt2 = new DataTable(); // Replace with Dt2

var result = dt1.AsEnumerable()
            .Union(dt2.AsEnumerable())
            .OrderBy (d => d.Field<string>("emp_name"));
like image 68
Razor Avatar answered Sep 28 '22 03:09

Razor


i think this code will help u to do it without using entity...

Dt1.Merge(Dt2);
like image 32
Fk Bey Avatar answered Sep 28 '22 03:09

Fk Bey