Hi....
I am working in ADO.NET and face a problem in Join and Union. How can we use join and union in ADO.NET ?
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Jignesh TrivediPosted Jan 16, 2012, 11:34 PM
you can join two table using LINQ to DataTable.
DataTable orders = ds.Tables["SalesOrderHeader"];
DataTable details = ds.Tables["SalesOrderDetail"];
var query =("SalesOrderID") equals("SalesOrderID")("OnlineOrderFlag") == true("OrderDate").Month == 8("SalesOrderID"),("SalesOrderDetailID"),("OrderDate"),("ProductID")
from order in orders.AsEnumerable()
join detail in details.AsEnumerable()
on order.Field
detail.Field
where order.Field
&& order.Field
select new
{
SalesOrderID =
order.Field
SalesOrderDetailID =
detail.Field
OrderDate =
order.Field
ProductID =
detail.Field
};
DataTable orderTable = query.CopyToDataTable();
union two table use "datatable.merge(datatable2)"
more detail please refer
http://msdn.microsoft.com/en-us/library/bb386921.aspx
http://msdn.microsoft.com/en-us/library/system.data.datatable.merge.aspx
Pravin MorePosted Jan 16, 2012, 11:32 PM
Below are the syntax to use Join and Union.
JOIN
Select * from Table1 t1 join Table2 t2 on t1.Column1=t2.Column1
Union
Select Column1,Column2 from Table1
Union
Select Column1,Column2 from Table2
Thanks,
Pravin.