Hi,
I have two tables that I create to display information in a DataGridView Control. Now I need to compare the fields of these two tables. It is somewhat like:
void SomeFunction()
{
for (int i = 0; i < tableA.Rows.Count ; i++)
{
DataRow rowA = tableA.Rows[ i ] ;
for (int j = 0; j < tableB.rows.count ; j++)
{
DataRow rowB = tableB.Rows[ j ];
if (rowA["Col1"].ToString().Equals(rowB["Col1"].ToString()))
DoSomeProcessing();
}
}
}
I am sure there are much more better and efficient ways to perform this comparison. I would appreciate if I can get some really good suggestions.
Thanks!

Efficient search
Echo
bklambdin
Doug DeBug
Darren Grove
cleaner code perhaps (untested):
foreach(DataRow currentRowA in tableA.Rows)
{
foreach(DataRow currentRowB in tableB.Rows)
{
if (currentRowA["Col1"].ToString().Equals(currentRowB["Col1"].ToString()))
{
DoSomeProcessing();
}
}
}
in terms of efficiency....will have a think about that. If you are going to be comparing row by row by column then this would be the way I believe.