<p>I built an application which displays the records from database in the window and checks the the database for new records every couple of seconds. The problem is that the window blinks each time I check for new records and I want to fix it. I have tried to compare the old datatable with the new one and refresh only if they are different.
Does anyone know what is the best practice for such cases? I tried to do it the following way but it doesn't work:</p>

<pre><code>private bool GetBelongingMessages()
        {
            bool result = false;
            DataTable dtTemp = OleDbWorks.GetBelongingMessages(currentCallID);
            if(dtTemp != dtMessages)
            {
                dtMessages = dtTemp;
                result = true;
            }
            else
            {
                result = false;
            }
            return result;
        }
</code></pre>

First off, it's important to recognize that what you're comparing in your code is the
references
of the datatables, not the
contents
of the datatables.  In order to determine if both datatables have the same contents, you're going to have to loop through all of the rows and columns and see if they're equal:
```
```
//This assumes the datatables have the same schema...
        public bool DatatablesAreSame(DataTable t1, DataTable t2) {         
            if (t1.Rows.Count != t2.Rows.Count)
                return false;

            foreach (DataColumn dc in t1.Columns) {
                for (int i = 0; i < t1.Rows.Count; i++) {
                    if (t1.Rows[i][dc.ColumnName] != t2.Rows[i][dc.ColumnName]) {
                        return false;
                    }
                }
            }
            return true;
        }
```
```