Applying join on two datatable in asp.net (c#) using LINQ.
Below is the Query :
1.LINQ Join Query:
DataTable result = (from t1 in SomeDatatable1.AsEnumerable()
join t2 in SomeDatatable2.AsEnumerable() on t1.Field<string>("EmpId") equals t2.Field<string>("EmpId")
select t1).CopyToDataTable();
2.LINQ Join with Where clause Query:
DataTable result = (from t1 in SomeDatatable1.AsEnumerable()
join t2 in SomeDatatable2.AsEnumerable() on t1.Field<string>("EmpId") equals t2.Field<string>("EmpId")
where t2.Field<string>("EmpId") == "100"
select t1).CopyToDataTable();
Below is the Query :
1.LINQ Join Query:
DataTable result = (from t1 in SomeDatatable1.AsEnumerable()
join t2 in SomeDatatable2.AsEnumerable() on t1.Field<string>("EmpId") equals t2.Field<string>("EmpId")
select t1).CopyToDataTable();
2.LINQ Join with Where clause Query:
DataTable result = (from t1 in SomeDatatable1.AsEnumerable()
join t2 in SomeDatatable2.AsEnumerable() on t1.Field<string>("EmpId") equals t2.Field<string>("EmpId")
where t2.Field<string>("EmpId") == "100"
select t1).CopyToDataTable();
No comments:
Post a Comment