I am having problem, i want to get the Intersected values of 2 datatables.
i am having 2 data tables with Data.
I want to get all the data which both table has in new table
Table 1 has columns= URL, Country, Source, Prevalence, Duration
Table 2 has coumns= ID, URL, Imp
so i want to get all the data from tables which have similar URLS
so in the New Table the columns will become = URL, Country, Source, Prevalence, Duration ,ID,Imp
Lets say first Table has 30000 Rows and 2nd Table has 14000 Rows. so in both tables 5000 Records are common which are in both tables (on the base of URL column) so i want those 5000 records in New column.
is there any way that i can get the Common records which are in both table in new table?
if somebody knows. Please Let me know. your help will be truly appreciated.
Thanks for paying attention to my questions. look forward to see your answers.
But, why do you have two DataTables? Would you be able to just get the data from a better query and only get the 5000 results instead? Sounds like a more common approach...
Have you read the book? - ASP.Net 3.5 CMS Development (now on Kindle)
v5.1 of iTracker (Inventory Tracker Starter Kit) is out, Download it now!
If your tables are both in the same data source, you should follow the advice given. However, if they are not. var q = from a in datatable1 Join b in datatable2 on a.url equals b.url into c Select c; Excuse crappy formatting, writing on an iPad!
If it helps, mark as answer - your approval helps with my recovery ;)
But, why do you have two DataTables? Would you be able to just get the data from a better query and only get the 5000 results instead? Sounds like a more common approach...
Well, data is coming from differnt files. thats why my application is suppose match that one.. i had a solution for Nested Loops. but that was pretty much slow. coz application has to make so many comparisons. so i impletemented that. didn't seem me good.
so afterwards i implemented that to insert all the data in the database and then make query and then do the same .. but data insertion was slow.. so finally i decided that use the Typed DataSets and DataTables put all the data in there and then make query
and after retriving the data store them in some DataTable and dispose off the previous one.. i think so there is only LINQ solution left.
but Thanks everyone for your replies.
Sheikh
Marked as answer by Mark - MSFT on Feb 19, 2013 05:27 AM
Sheikhans
Member
47 Points
85 Posts
How to Intersect 2 tables in C#
Feb 05, 2013 07:25 PM|LINK
Hello,
I am having problem, i want to get the Intersected values of 2 datatables.
i am having 2 data tables with Data.
I want to get all the data which both table has in new table
Table 1 has columns= URL, Country, Source, Prevalence, Duration
Table 2 has coumns= ID, URL, Imp
so i want to get all the data from tables which have similar URLS
so in the New Table the columns will become = URL, Country, Source, Prevalence, Duration ,ID,Imp
Lets say first Table has 30000 Rows and 2nd Table has 14000 Rows. so in both tables 5000 Records are common which are in both tables (on the base of URL column) so i want those 5000 records in New column.
is there any way that i can get the Common records which are in both table in new table?
if somebody knows. Please Let me know. your help will be truly appreciated.
Thanks for paying attention to my questions. look forward to see your answers.
Thanks
S
Curt_C
All-Star
66014 Points
7639 Posts
Moderator
Re: How to Intersect 2 tables in C#
Feb 05, 2013 08:04 PM|LINK
Nested Loops.....
But, why do you have two DataTables? Would you be able to just get the data from a better query and only get the 5000 results instead? Sounds like a more common approach...
v5.1 of iTracker (Inventory Tracker Starter Kit) is out, Download it now!
kidshaw
Participant
1158 Points
252 Posts
Re: How to Intersect 2 tables in C#
Feb 05, 2013 08:22 PM|LINK
jats_ptl
Member
378 Points
103 Posts
Re: How to Intersect 2 tables in C#
Feb 05, 2013 08:31 PM|LINK
Hello there,
You can use 2 methods for doing this that are as follows:
1: You can use Intersect Key word, which gives you common records.
SELECT column1 FROM table1 INTERSECT SELECT column1 FROM table22: Or else you can go with Inner Join method. For details of inner join go to following the link
http://databases.about.com/od/sql/l/aajoins2.htm
Hope you got the answer you are lookin for.
Thanks,
Jatin
Sheikhans
Member
47 Points
85 Posts
Re: How to Intersect 2 tables in C#
Feb 06, 2013 05:59 AM|LINK
Well, data is coming from differnt files. thats why my application is suppose match that one.. i had a solution for Nested Loops. but that was pretty much slow. coz application has to make so many comparisons. so i impletemented that. didn't seem me good. so afterwards i implemented that to insert all the data in the database and then make query and then do the same .. but data insertion was slow.. so finally i decided that use the Typed DataSets and DataTables put all the data in there and then make query and after retriving the data store them in some DataTable and dispose off the previous one.. i think so there is only LINQ solution left.
but Thanks everyone for your replies.
olemalik
Member
122 Points
98 Posts
Re: How to Intersect 2 tables in C#
Feb 06, 2013 07:25 AM|LINK