Depends on what your after but you could use INNER JOIN (although there are different types of JOIN) to join the IDs from each table i.e. the primary key from your main table to join with the Foreign Key on the secondary table and then return rows accordingly.
For more info on JOINS http://www.codeproject.com/Articles/33052/Visual-Representation-of-SQL-Joins
Pravind
Member
64 Points
230 Posts
Join on two datatables
Jul 11, 2012 04:59 PM|LINK
Hi,
can any1 help me on this?
I have three datatables DT1,DT2,DT3.
Iam populating data from threee different database tables into these tables.
How can i join these tables and run a query with some condition.All the three tables have Some relation.
Ex: primary Key DT1 wl be Foreign key in DT2....so on....I just want to work on these tables instead of again going to Database.
EssCee
Member
549 Points
765 Posts
Re: Join on two datatables
Jul 11, 2012 05:03 PM|LINK
Depends on what your after but you could use INNER JOIN (although there are different types of JOIN) to join the IDs from each table i.e. the primary key from your main table to join with the Foreign Key on the secondary table and then return rows accordingly. For more info on JOINS http://www.codeproject.com/Articles/33052/Visual-Representation-of-SQL-Joins
Pravind
Member
64 Points
230 Posts
Re: Join on two datatables
Jul 11, 2012 05:06 PM|LINK
Hi,
Thanks for reply, i dont want to know about joins, I just want to know
how can i Join the tables without going to database again.
I just want to do join on the resulted data which is stored in Datatables during runtime
Mudasir.Khan
All-Star
15346 Points
3142 Posts
Re: Join on two datatables
Jul 11, 2012 05:06 PM|LINK
select * from DATABASE1.dbo.DT1 dt1
join DATABASE2.dbo.DT2 dt2
on dt1.item_no = dt2.item_no
join DATABASE3.dbo.DT3 dt3
on dt1.item_no = dt3.item_no
Pravind
Member
64 Points
230 Posts
Re: Join on two datatables
Jul 11, 2012 05:12 PM|LINK
HI,
Thanks for reply.
Can you just eloborate the above query plz...
I just want to work on the resulted data tables instead of going to database again.Can you plz help me on this?
Allen Li - M...
Star
10411 Points
1196 Posts
Re: Join on two datatables
Jul 16, 2012 01:08 AM|LINK
Hi, you can get data with the SQL command, and then store them in ViewState. For example:
System.Data.DataTable MyTable = new System.Data.DataTable(); // You codes to get data from database here. ViewState["myTable"] = MyTable;If you have any feedback about my replies, please contact msdnmg@microsoft.com
Microsoft One Code Framework
hafizzeeshan
Participant
834 Points
253 Posts
Re: Join on two datatables
Jul 16, 2012 03:49 AM|LINK
Hi
Plz check the following link
http://www.w3schools.com/sql/sql_join_inner.asp
Regards
Zeeshan Rouf
Zeeshan Rauf
# 92-3216698206
Email : zeeshan_rouf@hotmail.com
Please mark the replies as answers if they help or unmark if not.
nageshrgosul
Participant
1044 Points
424 Posts
Re: Join on two datatables
Jul 16, 2012 05:03 AM|LINK
Hi,
select * from DT1 inner join DT2 inner join DT3 on Primarykeycolumname.DT1=foreignkeyofcolumnnane.DT2 on foreignkeycolumnname.DT3
Thank you
BlueCloud
Member
50 Points
15 Posts
Re: Join on two datatables
Jul 16, 2012 05:21 AM|LINK
I think you want to join two or more datatable objects without querying database.
Have a look up following link, hope it will help.
http://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/f122d7f4-3b7d-4d93-bd0f-8bb57cd990a4/