Efficient search

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!

[693 byte] By [akin_l] at [2007-12-26]
# 1

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.

ahmedilyas at 2007-9-4 > top of Msdn Tech,Visual C#,Visual C# General...
# 2
How about doing it in the database? SQL is pretty good at this :)
ChrisForbes at 2007-9-4 > top of Msdn Tech,Visual C#,Visual C# General...
# 3
doing what exactly in SQL?
ahmedilyas at 2007-9-4 > top of Msdn Tech,Visual C#,Visual C# General...
# 4
I am not working with a database. I create the tables as needed to display the data in DataGridView.
akin_l at 2007-9-4 > top of Msdn Tech,Visual C#,Visual C# General...