Sign In| Join
Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Jul 22, 2010 06:25 AM by sansan
Member
15 Points
23 Posts
Jul 21, 2010 05:26 AM|LINK
Dear All,
I want to get the unmatched records from DataTable1 by comparing DataTable2
eg :
Table 1
CallId Destination Call type
1 15515643 MOSE
2 16464996 MOSE
3 46169789 MOSTT
4 48892269 MOSTT
Table 2
1 15515643 Local
4 48892269 STD
I want to match the above two table by using column "CallId" and I want the result as Below
(Unmatched records of Table 1)
How can I achive this by using LINQ ?????????
Please Help......
unmatched records from DataTable1 by comparing DataTable2
All-Star
53942 Points
8147 Posts
Jul 21, 2010 06:19 AM|LINK
try this
http://www.dotnetspark.com/kb/705-compare-two-datatables-and-get-result.aspx
Jul 21, 2010 07:01 AM|LINK
assuming you have a unique key for the datatables and dt1, dt2 are the datatables.
List<DataRow> DifferentRows = new List<DataRow>(); List<DataRow> dt1Rows = dt1.Rows.OfType<DataRow>().ToList(); List<DataRow> dt2Rows = dt2.Rows.OfType<DataRow>().ToList(); DifferentRows.AddRange(dt1Rows.Where(a => (dt2Rows.FindAll(b => b["CallID"] == a["CallID"]).Count <= 0))); DifferentRows.AddRange(dt2Rows.Where(a => (dt1Rows.FindAll(b => b["CallID"] == a["CallID"]).Count <= 0)));
try that and see it works for you
Jul 21, 2010 07:59 AM|LINK
Hai,
Thanks for your response.
I use the above code but the system hangs at the execution of the below line
DifferentRows.AddRange(dt1Rows.Where(a => (dt2Rows.FindAll(b => b["CallID"] == a["CallID"]).Count <= 0)));
Plese guide me ...
Jul 21, 2010 08:03 AM|LINK
how many rows do you have in those DataTables.
Jul 21, 2010 08:19 AM|LINK
As of now i having 18000 rows. It may chance to more than this..
I feel there may be a error in the Lambda expression.
While i view the same line in the Quick watch i show the exception as "Expression cannot contain lambda expressions"
Jul 21, 2010 08:28 AM|LINK
I think it will take some time to compare as its a row by row comparison.
I'm not sure if there is any optimised way to do.
If you are using Oracle, you can easily do minus query
SELECT A,B FROM DUAL
MINUS
SELECT C,D FROM DUAL
I'll check if there is any other better method to do this
Jul 21, 2010 08:40 AM|LINK
Thanks for your reply.
I don't want to do this in backend (SQL). I try to achive this in LINQ itself..
Once again I thank you..
Jul 21, 2010 08:49 AM|LINK
Is there any chance to achive the result by using JOIN (Join the two DataTable) in LINQ ??
Jul 21, 2010 08:50 AM|LINK
mohanaraj@34...
Member
15 Points
23 Posts
get the unmatched records from DataTable1 by comparing DataTable2
Jul 21, 2010 05:26 AM|LINK
Dear All,
I want to get the unmatched records from DataTable1 by comparing DataTable2
eg :
Table 1
CallId Destination Call type
1 15515643 MOSE
2 16464996 MOSE
3 46169789 MOSTT
4 48892269 MOSTT
Table 2
CallId Destination Call type
1 15515643 Local
4 48892269 STD
I want to match the above two table by using column "CallId" and I want the result as Below
(Unmatched records of Table 1)
CallId Destination Call type
2 16464996 MOSE
3 46169789 MOSTT
How can I achive this by using LINQ ?????????
Please Help......
unmatched records from DataTable1 by comparing DataTable2
Mohanaraj S
email: mohanaraj@angleritech.com
sansan
All-Star
53942 Points
8147 Posts
Re: get the unmatched records from DataTable1 by comparing DataTable2
Jul 21, 2010 06:19 AM|LINK
try this
http://www.dotnetspark.com/kb/705-compare-two-datatables-and-get-result.aspx
sansan
All-Star
53942 Points
8147 Posts
Re: get the unmatched records from DataTable1 by comparing DataTable2
Jul 21, 2010 07:01 AM|LINK
assuming you have a unique key for the datatables and dt1, dt2 are the datatables.
try that and see it works for you
mohanaraj@34...
Member
15 Points
23 Posts
Re: get the unmatched records from DataTable1 by comparing DataTable2
Jul 21, 2010 07:59 AM|LINK
Hai,
Thanks for your response.
I use the above code but the system hangs at the execution of the below line
DifferentRows.AddRange(dt1Rows.Where(a => (dt2Rows.FindAll(b => b["CallID"] == a["CallID"]).Count <= 0)));
Plese guide me ...
Mohanaraj S
email: mohanaraj@angleritech.com
sansan
All-Star
53942 Points
8147 Posts
Re: get the unmatched records from DataTable1 by comparing DataTable2
Jul 21, 2010 08:03 AM|LINK
how many rows do you have in those DataTables.
mohanaraj@34...
Member
15 Points
23 Posts
Re: get the unmatched records from DataTable1 by comparing DataTable2
Jul 21, 2010 08:19 AM|LINK
Hai,
As of now i having 18000 rows. It may chance to more than this..
I feel there may be a error in the Lambda expression.
While i view the same line in the Quick watch i show the exception as "Expression cannot contain lambda expressions"
Mohanaraj S
email: mohanaraj@angleritech.com
sansan
All-Star
53942 Points
8147 Posts
Re: get the unmatched records from DataTable1 by comparing DataTable2
Jul 21, 2010 08:28 AM|LINK
I think it will take some time to compare as its a row by row comparison.
I'm not sure if there is any optimised way to do.
If you are using Oracle, you can easily do minus query
SELECT A,B FROM DUAL
MINUS
SELECT C,D FROM DUAL
I'll check if there is any other better method to do this
mohanaraj@34...
Member
15 Points
23 Posts
Re: get the unmatched records from DataTable1 by comparing DataTable2
Jul 21, 2010 08:40 AM|LINK
Thanks for your reply.
I don't want to do this in backend (SQL). I try to achive this in LINQ itself..
Once again I thank you..
Mohanaraj S
email: mohanaraj@angleritech.com
mohanaraj@34...
Member
15 Points
23 Posts
Re: get the unmatched records from DataTable1 by comparing DataTable2
Jul 21, 2010 08:49 AM|LINK
Hai,
Is there any chance to achive the result by using JOIN (Join the two DataTable) in LINQ ??
Mohanaraj S
email: mohanaraj@angleritech.com
mohanaraj@34...
Member
15 Points
23 Posts
Re: get the unmatched records from DataTable1 by comparing DataTable2
Jul 21, 2010 08:50 AM|LINK
Hai,
Is there any chance to achive the result by using JOIN (Join the two DataTable) in LINQ ??
Mohanaraj S
email: mohanaraj@angleritech.com