Click here to Skip to main content
15,887,436 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How to compare two datatables and highlight the particular cell WITHOUT USING LOOPS?
Posted
Updated 3-Apr-11 21: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.

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.
 
Share this answer
 
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.
 
Share this answer
 
Comments
BobJanova 4-Apr-11 5:58am    
I think you forgot to post the code under 'this may work:'.
dan!sh 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, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900