Click here to Skip to main content
14,363,472 members
Rate this:
Please Sign up or sign in to vote.
See more:
How to compare two datatables and highlight the particular cell WITHOUT USING LOOPS?
Posted
Updated 3-Apr-11 22:37pm
v2
Comments
BobJanova 4-Apr-11 6:00am
   
Why 'without using loops'? C# does most things like this with loops ...

Are the DataTables in memory or do you want to compare them with a database query? Are they the result of queries on the same table (i.e. you only need to check key fields)? Does order matter?
Ashishmau 4-Apr-11 6:51am
   
I want to compare two same datatables with some cells different and want to highlight that particular cell . I dont want to use looping as it will take more time if no. of rows increases.
Rate this:
Please Sign up or sign in to vote.

Solution 1

You could always write some logic to compare the collections behind the datagrids.
Once you know what is different, just change the colors of the cell for those values in the datagrid.
   
Rate this:
Please Sign up or sign in to vote.

Solution 2

You should describe what do you mean when you say compare. BTW if you need to know the differences, this may work:

If both the tables have same schema, then you can do this using ID comparison. Use LINQ to get the IDs in lists and then compare them using Except.
   
Comments
BobJanova 4-Apr-11 5:58am
   
I think you forgot to post the code under 'this may work:'.
lw@zi 4-Apr-11 6:23am
   
No. I posted the way for doing it rather than giving the code.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100